Creating a parse tree for a SQL statement

1k Views Asked by At

Given the following statement and ignoring any grammar concerns, what might be the most 'pure' way to parse the following SQL statement?

SELECT a, b AS x FROM tbl AS z

My thinking is something along the following:

               selectStatement
                     |
                  SELECT
                  /     \
            selectList  FROM
              /   \          \
     selectItem   selectItem  tableExpression
          |          /  \         |
          a         b   AS       tableItem
                         |     /     \
                         x  tbl      AS
                                      \
                                       z

Is that a more or less accurate representation of this? If not, where could it be improved? Sometimes I have a difficult time determining whether a keyword should be a parse node or not (for example should AS be a separate node, or should there just be some sort of label on the alias node, and are 'labels' valid in a parse tree?).

0

There are 0 best solutions below