pgsql: Fix attribute mapping for COPY TO on partitioned tables.

From: Masahiko Sawada <msawada(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix attribute mapping for COPY TO on partitioned tables.
Date: 2026-05-14 17:33:29
Message-ID: E1wNZw9-000XDI-1T@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix attribute mapping for COPY TO on partitioned tables.

Commit 4bea91f21f61 enabled COPY TO on a partitioned table to read
tuples from its partitions and mapped them to the root table's tuple
descriptor before output. However, it incorrectly built the attribute
map from the root table to the partition.

This commit fixes by building the attribute map from the partition to
the root table, ensuring that partition attributes are correctly
mapped to their corresponding root attributes.

Author: Chao Li <lic(at)highgo(dot)com>
Reviewed-by: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Reviewed-by: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Discussion: https://postgr.es/m/85EA70F3-C3DB-477B-B856-EA569FDAAE7C@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/82f0135a2630cc4465a8a424e38faf0f4e92f421

Modified Files
--------------
src/backend/commands/copyto.c | 4 ++--
src/test/regress/expected/copy.out | 11 +++++++++++
src/test/regress/sql/copy.sql | 9 +++++++++
3 files changed, 22 insertions(+), 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Nathan Bossart 2026-05-14 18:13:14 pgsql: refint: Fix segfault in check_foreign_key().
Previous Message Alexander Korotkov 2026-05-14 12:08:48 pgsql: Prevent access to other sessions' temp tables