Fix parsing of parenthesised OLD/NEW in RETURNING list. When parsing expressions like (old).colname and (old).* in a RETURNING list, the parser would lose track of the intended varreturningtype, and therefore return incorrect results.
The root cause was code using GetNSItemByRangeTablePosn() to find a namespace item from its rtindex and levelsup, without taking into account returningtype, which would return the wrong namespace item. Fix by adding a new function GetNSItemByVar() that does take returningtype into account. Backpatch to v18, where support for RETURNING OLD/NEW was added. Bug: #19516 Reported-by: Marko Grujic <[email protected]> Author: Marko Grujic <[email protected]> Suggested-by: Dean Rasheed <[email protected]> Reviewed-by: Dean Rasheed <[email protected]> Discussion: https://postgr.es/m/CAOvwyF2cO_5mAt=w=y-dfnag5ukz+3h8nsdokf_iuwzhsu2...@mail.gmail.com Backpatch-through: 18 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/79c65b9d97fe92ea2792be09479cf4bbea7cefe1 Modified Files -------------- src/backend/parser/parse_coerce.c | 9 ++++----- src/backend/parser/parse_func.c | 4 +--- src/backend/parser/parse_relation.c | 32 ++++++++++++++++++++++++++++++++ src/backend/parser/parse_target.c | 2 +- src/include/parser/parse_relation.h | 1 + src/test/regress/expected/returning.out | 25 +++++++++++++++++++++++++ src/test/regress/sql/returning.sql | 11 +++++++++++ 7 files changed, 75 insertions(+), 9 deletions(-)
