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/[email protected] Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/cf588e10f664be37a0804e9a8662facd0e163800 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(-)
