Re: Is "WITH RECURSIVE" limited to the first position of CTEs by design?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Kirk Wolak <wolakk(at)gmail(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Is "WITH RECURSIVE" limited to the first position of CTEs by design?
Date: 2023-11-13 16:49:03
Message-ID: 2073791.1699894143@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Mon, Nov 13, 2023 at 9:17 AM Kirk Wolak <wolakk(at)gmail(dot)com> wrote:
>> These are the most trivial examples. The second one results in a syntax
>> error. Which implies that:
>> 1) There can only be one recursive CTE at the same level?
>> 2) It must be the FIRST CTE?

> There is only one WITH keyword as well, that doesn't change the fact there
> can be multiple attached queries to it.

Yeah, RECURSIVE is attached to the WITH not to the query. That's
because it has global implications for the visibility of the CTE
names across all the CTEs in the WITH.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2023-11-13 17:00:39 Re: Issue in compiling postgres on latest macOS 14.1.1
Previous Message Adrian Klaver 2023-11-13 16:47:03 Re: Unique Primary Key Linked to Multiple Accounts