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 <[email protected]> Author: Zsolt Parragi <[email protected]> Discussion: https://postgr.es/m/[email protected] 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(+)
