Question about the traverse method on v6
Closed this issue · 4 comments
rodolfolottin commented
Hi! I'm currently migrating a Python app from Python 3.9 to Python 3.12. However, I'm encountering an issue while attempting to port the following code:
for query in queries:
for node in pglast.node.Node(pglast.parser.parse_sql(query)[0]).traverse():
if isinstance(node, pglast.node.Scalar):
continue
Specifically, I'm unable to determine how to traverse the query, generate AST nodes and iterate over each element. Has this functionality been included in the latest version?
lelit commented
The functionality has been reimplemented with the visitor pattern:
from pglast import parse_sql
from pglast.visitors import Visitor
class VerboseVisitor(Visitor):
def visit(self, ancestors, node):
print("node:", type(node).__name__,
"ancestor:", type(ancestors.node).__name__)
vv = VerboseVisitor()
vv(parse_sql('select foo from bar'))
Unfortunately I notice that the related doc page comes out empty 😭
Will check.
lelit commented
In the meantime, you can read the v4 visitors page, nothing [substantial] changed between v4 and v6, AFAICT.
lelit commented
I fixed the build on rtd.org, see the v6 visitors page.
Let me know if you need further help.
rodolfolottin commented
Thank you very much!