pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix MERGE into inheritance parent with extra child columns.
Date: Thu, 12 Nov 2026 21:22:16 +0000
Message-ID: <E1xRcFM-00000000Tzs-1XIF@gemulon.postgresql.org> (raw)

Fix MERGE into inheritance parent with extra child columns.

When a MERGE with INSERT actions targets the parent of an inheritance
tree, and the parent itself is excluded by constraint exclusion, and
the first child table has extra columns, the command would fail during
initialization, while attempting to convert the child row type to the
parent.

Fix in ExecInitMerge() by calling build_attrmap_by_name() with
missing_ok = true to build the child-to-parent attribute map --- that
code (added by commit b006bcd5310) deals exclusively with plain
inheritance, not partitioning, so the child table may have extra
columns, which can be safely ignored, since they cannot be referenced
in the main query.

Backpatch to v15, where MERGE was introduced.

Reported-by: Tender Wang <tndrwang@gmail.com>
Author: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Keyerror Smart <smartkeyerror@gmail.com>
Discussion: https://postgr.es/m/CAHewXNm-SQqJ6UeT2sTb4q-CUVyA3NN7tKgcSmPRjYFoZQvdGA%40mail.gmail.com
Backpatch-through: 15

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5ea558ef761f882cae7087e60d4422cce7eeae48

Modified Files
--------------
src/backend/access/common/attmap.c     | 18 +++++++++++++++++-
src/backend/executor/nodeModifyTable.c | 12 +++++++++---
src/include/access/attmap.h            |  3 +++
src/test/regress/expected/merge.out    | 18 ++++++++++++++++++
src/test/regress/sql/merge.sql         | 20 ++++++++++++++++++++
5 files changed, 67 insertions(+), 4 deletions(-)



view thread (6+ messages)

Message-ID: <E1xRcFM-00000000Tzs-1XIF@gemulon.postgresql.org>
Permalink:  ../E1xRcFM-00000000Tzs-1XIF@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xRcFM-00000000Tzs-1XIF@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: dean.a.rasheed@gmail.com
  Subject: Re: pgsql: Fix MERGE into inheritance parent with extra child columns.
  In-Reply-To: <E1xRcFM-00000000Tzs-1XIF@gemulon.postgresql.org>
  References: <E1xRcFM-00000000Tzs-1XIF@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