pgsql: Improve error for RETURNING with system columns under rules

Started by Michael Paquier3 months ago1 messagescommitters
Jump to latest
#1Michael Paquier
michael@paquier.xyz

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: /messages/by-id/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(+)