mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
Fix inability to reference CYCLE column from inside its CTE.
Such references failed with "cache lookup failed for type 0" because we didn't resolve the type of the CYCLE column until after analyzing the CTE's query. We can just move that processing to before the recursive parse_sub_analyze call, though. While here, invent a couple of local variables to make this code less egregiously wider-than-80-columns. Per bug #17723 from Vik Fearing. Back-patch to v14 where the CYCLE feature was added. Discussion: https://postgr.es/m/17723-2c4985ff111e7bba@postgresql.org
This commit is contained in:
@@ -1221,6 +1221,29 @@ select * from test;
|
||||
0 | t | {(0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(0)}
|
||||
(11 rows)
|
||||
|
||||
with recursive test as (
|
||||
select 0 as x
|
||||
union all
|
||||
select (x + 1) % 10
|
||||
from test
|
||||
where not is_cycle -- redundant, but legal
|
||||
) cycle x set is_cycle using path
|
||||
select * from test;
|
||||
x | is_cycle | path
|
||||
---+----------+-----------------------------------------------
|
||||
0 | f | {(0)}
|
||||
1 | f | {(0),(1)}
|
||||
2 | f | {(0),(1),(2)}
|
||||
3 | f | {(0),(1),(2),(3)}
|
||||
4 | f | {(0),(1),(2),(3),(4)}
|
||||
5 | f | {(0),(1),(2),(3),(4),(5)}
|
||||
6 | f | {(0),(1),(2),(3),(4),(5),(6)}
|
||||
7 | f | {(0),(1),(2),(3),(4),(5),(6),(7)}
|
||||
8 | f | {(0),(1),(2),(3),(4),(5),(6),(7),(8)}
|
||||
9 | f | {(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)}
|
||||
0 | t | {(0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(0)}
|
||||
(11 rows)
|
||||
|
||||
-- multiple CTEs
|
||||
with recursive
|
||||
graph(f, t, label) as (
|
||||
|
@@ -605,6 +605,15 @@ with recursive test as (
|
||||
) cycle x set is_cycle using path
|
||||
select * from test;
|
||||
|
||||
with recursive test as (
|
||||
select 0 as x
|
||||
union all
|
||||
select (x + 1) % 10
|
||||
from test
|
||||
where not is_cycle -- redundant, but legal
|
||||
) cycle x set is_cycle using path
|
||||
select * from test;
|
||||
|
||||
-- multiple CTEs
|
||||
with recursive
|
||||
graph(f, t, label) as (
|
||||
|
Reference in New Issue
Block a user