Question: Extracted all input tables #525
-
Hi all, first of all, many thanks for this amazing parser! With following code, from sqlglot import parse_one, exp stmt = """ I get: derived_table Is there a way to only extract the "real" input table t_1 and t_2 by omitting the derived_table? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
hi there, probably not the best solution, but this does the trick :D
|
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
Scope is a good way to do this:
We should probably add these as little utility functions in sqlglot. I copied this code from my own application.