From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improve error for RETURNING with system columns under rules
Date: Thu, 20 Aug 2026 22:51:52 +0000
Message-ID: <E1wxBby-00000001Q20-45G0@gemulon.postgresql.org> (raw)
Improve error for RETURNING with system columns under rules
When a DML query's RETURNING list references the system column of a
target table, and the query was rewritten by a rule with its own
RETURNING clause, ReplaceVarsFromTargetList() failed with an internal
error "could not find replacement targetlist entry for attno -1",
since the rule's RETURNING list only has entries for user columns.
Such queries cannot work: the rewritten query need not scan the original
target relation at all, so a rule's RETURNING list has no way to provide
values for that relation's system columns.
This is a life improvement change as the error reported is just more
relevant for the user and this has never worked since RETURNING is
reported. No backpatch is done, based on the lack of complaints over
the ages.
Reported-by: Zheng Wang <hackerzheng666@gmail.com>
Author: Zsolt Parragi <zsolt.parragi@percona.com>
Discussion: https://postgr.es/m/19632-9155d9baec763c8c@postgresql.org
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/d39762b8c79a8a825be4af0a22b048a18483afa3
Modified Files
--------------
src/backend/rewrite/rewriteManip.c | 13 +++++++++++++
src/test/regress/expected/returning.out | 7 +++++++
src/test/regress/sql/returning.sql | 5 +++++
3 files changed, 25 insertions(+)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Improve error for RETURNING with system columns under rules
In-Reply-To: <E1wxBby-00000001Q20-45G0@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox