pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Langote <amitlan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix multi-row INSERT with a sublink in a target column subscript
Date: Wed, 04 Nov 2026 23:18:11 +0000
Message-ID: <E1xOkFA-00000000EFV-0KGG@gemulon.postgresql.org> (raw)

Fix multi-row INSERT with a sublink in a target column subscript

For INSERT ... VALUES with more than one row, transformInsertStmt()
calls transformInsertRow() once for each VALUES row and once more for
the final targetlist, and each call transformed the same raw
indirection from the target column list.  That doesn't work for
sublinks, because transformSubLink() replaces the raw subselect with
its analyzed Query, so the second pass failed with "unexpected
non-SELECT command in SubLink".  Other nodes that are transformed in
place, such as NullTest, failed with "unrecognized node type".

Fix by giving each transformation its own copy of the indirection.

Claude found this issue when reviewing another bug.

Discussion: https://postgr.es/m/CA+HiwqHCZLZV_20nz3fQX+1=vyFLDMbG0_3wY=QujNKZWts0nw@mail.gmail.com
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Shihao Zhong <zhong950419@gmail.com>
Backpatch-through: 14

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2dd680013e75e04e510a48968439ee704c6d456e

Modified Files
--------------
src/backend/parser/analyze.c         |  8 +++++++-
src/test/regress/expected/insert.out | 10 ++++++++++
src/test/regress/sql/insert.sql      |  4 ++++
3 files changed, 21 insertions(+), 1 deletion(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1xOkFA-00000000EFV-0KGG@gemulon.postgresql.org>
Permalink:  ../E1xOkFA-00000000EFV-0KGG@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xOkFA-00000000EFV-0KGG@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: amitlan@postgresql.org
  Subject: Re: pgsql: Fix multi-row INSERT with a sublink in a target column subscript
  In-Reply-To: <E1xOkFA-00000000EFV-0KGG@gemulon.postgresql.org>
  References: <E1xOkFA-00000000EFV-0KGG@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