Skip to content

Question: Extracted all input tables #525

Closed Answered by barakalon
netplanet1981 asked this question in Q&A
Discussion options

You must be logged in to vote

Scope is a good way to do this:

from sqlglot import expressions as exp
from sqlglot.optimizer.scope import traverse_scope

[
    source
    for scope in traverse_scope(expression)
    for source in scope.sources.values()
    if isinstance(source, exp.Table)
]

We should probably add these as little utility functions in sqlglot. I copied this code from my own application.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by barakalon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants