此查询生成从 1 到 4 的数字。
with recursive z(q) as (
select 1
union all
select q + 1 from z where q < 4
)
select * from z;
但是,如果我修改成这样,
with x as (
select 1 y
),
recursive z(q) as (
select y from x
union all
select q + 1 from z where q < 4
)
select * from z;
它给了
ERROR: syntax error at or near "z"
我做错了什么?
最佳答案
我认为这是因为RECURSIVE is modifier of WITH statement ,不是公用表表达式 z
的属性,因此您可以像这样使用它:
with recursive
x as (
select 1 y
),
z(q) as (
select y from x
union all
select q + 1 from z where q < 4
)
select * from z;
关于sql - PostgreSQL 中的递归 CTE 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19420168/