Issue accessing parts of the parsed SQL query tree using sqlglot.parse() #4736
-
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: The JOINs present in the query. 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.
Replies: 1 comment
-
Read this guide https://github.com/tobymao/sqlglot/blob/main/posts/ast_primer.md |
Beta Was this translation helpful? Give feedback.
Read this guide
https://github.com/tobymao/sqlglot/blob/main/posts/ast_primer.md