Issue accessing parts of the parsed SQL query tree using sqlglot.parse() #4736
Replies: 1 comment
-
Read this guide https://github.com/tobymao/sqlglot/blob/main/posts/ast_primer.md |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am using the sqlglot library to parse a complex SQL query, but I am encountering issues when trying to access specific parts of the parsed tree. When I execute sqlglot.parse(query), I get an object of type sqlglot.expressions.Select, but when iterating over this object, I can only access the columns (Column), and I cannot seem to access other elements such as JOINs, WHERE, and WITH, even though I know they are present in the query.
Expected Outcome:
I would like to be able to access the following parts of the parsed tree:
The JOINs present in the query.
The WHERE clause.
The WITH clause (CTE).
I have tried several ways to access the joins, where, and with properties of the Select object, but have not been successful. For example:
I have verified that the parsed tree contains the JOINs, WHERE, and WITH, but I am unable to access these parts.
Here’s the result when I print the parsed variable:
Based on this output, I can see that the parsed object contains the JOIN, WHERE, and WITH parts. However, I am unable to directly access them.
Has anyone encountered this issue before or could someone help me figure out how to access these parts of the parsed query?
Beta Was this translation helpful? Give feedback.
All reactions