pgsql: Avoid unhelpful internal error for incorrect recursive-WITH quer

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid unhelpful internal error for incorrect recursive-WITH quer
Date: 2024-07-14 17:50:04
Message-ID: E1sT3MK-001eq5-Dg@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f96c2c72788cab3005c8bc6b4934b4928b34a529

Modified Files
--------------
src/backend/parser/parse_cte.c | 53 ++++++++++++++++++++++++--------------
src/test/regress/expected/with.out | 40 ++++++++++++++++++++++++++++
src/test/regress/sql/with.sql | 29 +++++++++++++++++++++
3 files changed, 102 insertions(+), 20 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Richard Guo 2024-07-15 01:27:29 pgsql: Check lateral references within PHVs for memoize cache keys
Previous Message Andrew Dunstan 2024-07-13 20:24:06 pgsql: Use correct collate.windows.win1252.out