First attempt of supporting CTE#14771
Conversation
|
For the reference (that both x AS subquery and subquery AS x are Ok): |
|
For the reference cond. |
|
It seems slightly confusing to me. with
x1 as (select 1) -- syntax #1
select
...
from
x1,
(select 2) as x2, -- syntax #2
x3 as (select 3) -- error?I would suggest something like this: with query
(select 1) as x
with
(select 1) as y
select
y
from
x |
That's more complicated and not similar to any standard.
It's consistent with other databases. |
| with_element->subquery = subquery; | ||
| node = with_element; | ||
| } | ||
| else |
There was a problem hiding this comment.
It is inconsistent that not everything in WITH is parsed as ASTWithElement.
|
|
||
| namespace DB | ||
| { | ||
| // TODO After we support `union_with_global`, this visitor should also be extended to match ASTSelectQueryWithUnion. |
There was a problem hiding this comment.
BTW it will be something like with_global because it will apply for all subqueries with correct scoping:
WITH 1 AS x SELECT x;
WITH 1 AS x SELECT * FROM (SELECT x);
WITH 1 AS x SELECT *, x FROM (WITH 2 AS x SELECT x AS y);
|
The |
|
Describe, please, how this PR closes #2416? |
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Now we support
WITH <identifier> AS (subquery) ...to introduce named subqueries in the query context. This closes #2416. This closes #4967.Detailed description / Documentation draft:
Non-recursive CTE introduces named subqueries to the current and children query context. Those identifiers can appear in places where table objects are allowed. Recursion is prevented by hiding the current level CTEs from the WITH expression.