I'm trying to use a recursive CTE in the from clause in DB2 luw 11.1. This CTE works by itself:
with i (i) as (
values (1)
union all
select i + 1 from i
where i < 3
)
select * from i;
I
-------------
1
2
3
But when I try it in the from clause:
select *
from (
with i (i) as (
values (1)
union all
select i + 1 from i
where i < 3
)
select * from i
) i;
ERRO próximo da linha 1:
SQL0104N An unexpected token "as" was found following "*
from (
with i (i)". Expected tokens may include: "JOIN".
A similar construct works in Postgresql. What am I missing?
FROMclause? Looks like an X-Y problem to me. As you can see, it's syntactically incorrect in DB2 (and semantically unnecessary).