pgsql: Fix COPY TO FORMAT JSON to exclude generated columns.

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix COPY TO FORMAT JSON to exclude generated columns.
Date: 2026-04-15 11:59:12
Message-ID: E1wCytk-0015Dl-0V@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix COPY TO FORMAT JSON to exclude generated columns.

COPY TO with FORMAT json was including generated columns in the
output, unlike TEXT and CSV formats. Virtual generated columns
appeared as null, and stored ones showed their computed values.

The JSON code path only built a restricted TupleDesc when an explicit
column list was given (attnamelist != NIL), but CopyGetAttnums()
also excludes generated columns from the default list. Fix by
checking whether the attnumlist is shorter than the full TupleDesc
instead.

Bug introduced in 7dadd38cda9.

Author: Satya Narlapuram <satya(dot)narlapuram(at)gmail(dot)com>
Reviewed-by: Jian He <jian(dot)universality(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAHg+QDcfpGDoPL3fvfjXRtfn=fny6DdJR6BAy6TpS1Xj2EZfXA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f30d0c720f2ec979ab1b5b44b1f9f201d6efdf8c

Modified Files
--------------
src/backend/commands/copyto.c | 2 +-
src/test/regress/expected/generated_stored.out | 6 ++++++
src/test/regress/expected/generated_virtual.out | 6 ++++++
src/test/regress/sql/generated_stored.sql | 3 +++
src/test/regress/sql/generated_virtual.sql | 3 +++
5 files changed, 19 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Bruce Momjian 2026-04-15 17:03:51 pgsql: doc PG 19 relnotes: adjust ShmemRequestStruct item
Previous Message Andrew Dunstan 2026-04-15 11:36:59 pgsql: Rework signal handler infrastructure to pass sender info as argu