pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: COPY TO FORMAT JSON: use the query's column names as keys 2+ messages / 1 participants [nested] [flat]
* pgsql: COPY TO FORMAT JSON: use the query's column names as keys @ 2026-10-08 17:41 Andrew Dunstan <andrew@dunslane.net> 0 siblings, 0 replies; 2+ messages in thread From: Andrew Dunstan @ 2026-10-08 17:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org COPY TO FORMAT JSON: use the query's column names as keys CopyToJsonOneRow() stamped the row datum with the query's descriptor only when the slot's descriptor was of type RECORD. A scan that does not project returns the table's row type, so the keys came from the table, not the query, losing column aliases and mislabelling rows from UNION ALL branches with different column orders. Fix by always using the query's descriptor. For non-virtual slots, heap_copy_tuple_as_datum() can just be passed that descriptor, so there is no extra cost. This is safe because a scan skips projection only when tlist_matches_tupdesc() holds, so the layouts match. Bug introduced in 7dadd38cda9. Reported-by: Shihao Zhong <zhong950419@gmail.com> Reviewed-by: Shihao Zhong <zhong950419@gmail.com> Reviewed-by: João Marcelo Detomini <joao.detomini@enterprisedb.com> Discussion: https://postgr.es/m/CAGRkXqQHjxgufHPz86+dxGaQZt37hikduUArYtfbn2_3mryZAw@mail.gmail.com Backpatch-through: 19 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/c652cd3f94d57e69965f065c4ed45708a2b2a757 Modified Files -------------- src/backend/commands/copyto.c | 40 ++++++++++++++++++++++++++------------ src/test/regress/expected/copy.out | 13 +++++++++++++ src/test/regress/sql/copy.sql | 10 ++++++++++ 3 files changed, 51 insertions(+), 12 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: COPY TO FORMAT JSON: use the query's column names as keys @ 2026-10-08 17:41 Andrew Dunstan <andrew@dunslane.net> 0 siblings, 0 replies; 2+ messages in thread From: Andrew Dunstan @ 2026-10-08 17:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org COPY TO FORMAT JSON: use the query's column names as keys CopyToJsonOneRow() stamped the row datum with the query's descriptor only when the slot's descriptor was of type RECORD. A scan that does not project returns the table's row type, so the keys came from the table, not the query, losing column aliases and mislabelling rows from UNION ALL branches with different column orders. Fix by always using the query's descriptor. For non-virtual slots, heap_copy_tuple_as_datum() can just be passed that descriptor, so there is no extra cost. This is safe because a scan skips projection only when tlist_matches_tupdesc() holds, so the layouts match. Bug introduced in 7dadd38cda9. Reported-by: Shihao Zhong <zhong950419@gmail.com> Reviewed-by: Shihao Zhong <zhong950419@gmail.com> Reviewed-by: João Marcelo Detomini <joao.detomini@enterprisedb.com> Discussion: https://postgr.es/m/CAGRkXqQHjxgufHPz86+dxGaQZt37hikduUArYtfbn2_3mryZAw@mail.gmail.com Backpatch-through: 19 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/05b522024838e19f7b9f0fe54d72b29bc588b230 Modified Files -------------- src/backend/commands/copyto.c | 40 ++++++++++++++++++++++++++------------ src/test/regress/expected/copy.out | 13 +++++++++++++ src/test/regress/sql/copy.sql | 10 ++++++++++ 3 files changed, 51 insertions(+), 12 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-10-08 17:41 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-10-08 17:41 pgsql: COPY TO FORMAT JSON: use the query's column names as keys Andrew Dunstan <andrew@dunslane.net> 2026-10-08 17:41 pgsql: COPY TO FORMAT JSON: use the query's column names as keys Andrew Dunstan <andrew@dunslane.net>
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