update the existing CTE in with clause if the cte is already present #2737
Replies: 1 comment
-
already answered in slack i believe https://github.com/tobymao/sqlglot/blob/main/posts/ast_primer.md |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I want to update the existing CTE in with clause if the cte is already present. is it possible ?
a=select("x").with_("tbl", as_=select("x").from_("tb"))
print(a.sql())
b = a.with_("tb2", as_=select("x").from_("tb1"))
print(b.sql())
c = b.with_("tb2", as_=select("x").from_("tb1"))
print(c.sql())
prints:
WITH tbl AS (SELECT x FROM tb) SELECT x
WITH tbl AS (SELECT x FROM tb), tb2 AS (SELECT x FROM tb1) SELECT x
WITH tbl AS (SELECT x FROM tb), tb2 AS (SELECT x FROM tb1), tb2 AS (SELECT x FROM tb1) SELECT x
I want:
WITH tbl AS (SELECT x FROM tb) SELECT x
WITH tbl AS (SELECT x FROM tb), tb2 AS (SELECT x FROM tb1) SELECT x
WITH tbl AS (SELECT x FROM tb), tb2 AS (SELECT x FROM tb1) SELECT x
Beta Was this translation helpful? Give feedback.
All reactions