Re: BUG #18536: Using WITH inside WITH RECURSIVE triggers a "shouldn't happen" error

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: exclusion@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2024-07-14T17:01:32Z
Lists: pgsql-bugs

Attachments

I wrote:
> I think the case you show should be throwing
> ERROR:  recursive query "t" does not have the form non-recursive-term UNION [ALL] recursive-term

Hmm, that is probably too strong: it will break some queries we've
historically accepted.  What we need is just to forbid self-references
within the WITH clause.  The code actually does that already, it's
just doing it too late; so we can fix this with a simple re-ordering
of the error checks, as attached.

			regards, tom lane

Commits

  1. Avoid unhelpful internal error for incorrect recursive-WITH queries.