]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Avoid unhelpful internal error for incorrect recursive-WITH queries.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 14 Jul 2024 17:49:46 +0000 (13:49 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 14 Jul 2024 17:49:46 +0000 (13:49 -0400)
commitb020a866a22b40138161c70351da375f2d2bd24f
tree8f5164a5d637001fbe62b2f7d50204c05769f5f9
parent2423c84d098ab47ae540bc88a29bcb6fb3812e60
Avoid unhelpful internal error for incorrect recursive-WITH queries.

checkWellFormedRecursion would issue "missing recursive reference"
if a WITH RECURSIVE query contained a single self-reference but
that self-reference was inside a top-level WITH, ORDER BY, LIMIT,
etc, rather than inside the second arm of the UNION as expected.
We already intended to throw more-on-point errors for such cases,
but those error checks must be done before examining the UNION arm
in order to have the desired results.  So this patch need only
move some code (and improve the comments).

Per bug #18536 from Alexander Lakhin.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/18536-0a342ec07901203e@postgresql.org
src/backend/parser/parse_cte.c
src/test/regress/expected/with.out
src/test/regress/sql/with.sql