Bug: COPY FORMAT JSON includes generated columns unlike text/CSV

From: SATYANARAYANA NARLAPURAM <satyanarlapuram(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Richard Guo <guofenglinux(at)gmail(dot)com>
Subject: Bug: COPY FORMAT JSON includes generated columns unlike text/CSV
Date: 2026-04-13 09:21:28
Message-ID: CAHg+QDcfpGDoPL3fvfjXRtfn=fny6DdJR6BAy6TpS1Xj2EZfXA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

COPY TO with FORMAT json includes generated columns in the output,
while text and CSV formats correctly exclude them. Virtual generated
columns appear as null (since they aren't materialized), and stored
generated columns appear with their values Attached a patch to address
this.

Repro:

CREATE TABLE t (id int, a int,
s int GENERATED ALWAYS AS (a * 10) STORED,
v int GENERATED ALWAYS AS (a * 100) VIRTUAL);
INSERT INTO t (id, a) VALUES (1, 5);

COPY t TO STDOUT;
COPY t TO STDOUT WITH (FORMAT csv, HEADER);
COPY t TO STDOUT WITH (FORMAT json);
CREATE TABLE
INSERT 0 1
1 5
id,a
1,5
{"id":1,"a":5,"s":50,"v":null}

After the fix:
COPY t TO STDOUT WITH (FORMAT json);
{"id":1,"a":5}

Thanks,
Satya

Attachment Content-Type Size
v1-00001-copy-json-exclude-generated-columns.patch application/octet-stream 3.0 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2026-04-13 09:24:14 Re: [Proposal] Adding Log File Capability to pg_createsubscriber
Previous Message Peter Eisentraut 2026-04-13 09:21:23 Re: Unicode update and some tooling improvements