Sergey Ivanov
Sergey Ivanov

Reputation: 71

WITH RECURSIVE as second part CTE in query. Postgres

How I can write a query like that:

with t1 as 
(
select id 
from table1
),
RECURSIVE t2(
select * from t2
union
...
)

Currently it's not allowed?

Upvotes: 7

Views: 2220

Answers (1)

user330315
user330315

Reputation:

The recursive needs to be right after the WITH regardless on where you put the recursive CTE:

with recursive t1 as 
(
  select id 
  from table1
), t2 (
  select *  
  from t2
  union
  ...
)
...

Upvotes: 12

Related Questions