agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix parsing of parenthesised OLD/NEW in RETURNING list.
Date: Thu, 11 Jun 2026 11:10:54 +0000
Message-ID: <E1wXdJG-001znU-1Z@gemulon.postgresql.org> (raw)

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 <markoog@gmail.com>
Author: Marko Grujic <markoog@gmail.com>
Suggested-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Discussion: https://postgr.es/m/CAOvwyF2cO_5mAt=w=y-dFnaG5UkZ+3H8nSDoKF_iuWZHsU2ARg@mail.gmail.com
Backpatch-through: 18

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9108fed3eda97475d5ef2f9060f6bc1f61783346

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(-)



view thread (2+ messages)

Message-ID: <E1wXdJG-001znU-1Z@gemulon.postgresql.org>
Permalink:  ../E1wXdJG-001znU-1Z@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wXdJG-001znU-1Z@gemulon.postgresql.org

reply

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: dean.a.rasheed@gmail.com, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix parsing of parenthesised OLD/NEW in RETURNING list.
  In-Reply-To: <E1wXdJG-001znU-1Z@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox