-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
Before you file an issue
- Make sure you specify the "read" dialect eg.
parse_one(sql, read="spark") - Make sure you specify the "write" dialect eg.
ast.sql(dialect="duckdb") - Check if the issue still exists on main
Fully reproducible code snippet
Please include a fully reproducible code snippet or the input sql, dialect, and expected output.
Official Documentation
Please include links to official SQL documentation related to your issue.
The WITH and CTE expressions are different when they are added with with_ method, compared with parsing from original query.
Below code can be used to see the differences.
from sqlglot import parse_one
from sqlglot.diff import diff, Keep
cte_query = "SELECT a.x FROM a"
main_query = "SELECT x FROM cte"
full_query = "WITH cte AS (SELECT a.x FROM a) SELECT x FROM cte"
cte_tree = parse_one(cte_query)
from_cte = parse_one(main_query).with_(alias="cte", as_=cte_tree)
from_str = parse_one(full_query)
delta = [d for d in diff(from_cte, from_str) if not isinstance(d, Keep)]Two queries/syntax trees are semantically the same, but diff function returns 2 Update:
WITHstatement. When assembly CTE withwith_function, it addedrecursivekey, and set the default valueFalse.
CTEstatemtn. When assembly CTE withwith_function, it added 'scalarkey, and set the default valueFalse`

Metadata
Metadata
Assignees
Labels
No labels