From fa6624a228e892a87a8e97d6a0374df150258bd0 Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Mon, 5 Oct 2026 11:44:14 -0400 Subject: [PATCH v1 2/2] Add tests for JSON keys of COPY (query) TO Check that the keys are the query's column names when the scan does not project, with column aliases and with UNION ALL over tables whose column names differ. --- src/test/regress/expected/copy.out | 9 +++++++++ src/test/regress/sql/copy.sql | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/test/regress/expected/copy.out b/src/test/regress/expected/copy.out index 0af0b646921..ea34bb3337d 100644 --- a/src/test/regress/expected/copy.out +++ b/src/test/regress/expected/copy.out @@ -117,6 +117,15 @@ copy (select * from copytest) to stdout (format json); {"style":"Unix","test":"abc\ndef","filler":2} {"style":"Mac","test":"abc\rdef","filler":3} {"style":"esc\\ape","test":"a\\r\\\r\\\n\\nb","filler":4} +-- keys are the query's column names, also when a scan does not project +copy (select a as x, b as y, c as z from copytest_order) to stdout (format json); +{"x":1,"y":2,"z":3} +create temp table copytest_order2 (c int, b int, a int); +insert into copytest_order2 values (4, 5, 6); +copy (select * from copytest_order union all select * from copytest_order2) + to stdout (format json); +{"a":1,"b":2,"c":3} +{"a":4,"b":5,"c":6} -- all of the following should yield error copy copytest to stdout (format json, delimiter '|'); ERROR: cannot specify DELIMITER in JSON mode diff --git a/src/test/regress/sql/copy.sql b/src/test/regress/sql/copy.sql index 14da3c5ec37..ec6ff8482bd 100644 --- a/src/test/regress/sql/copy.sql +++ b/src/test/regress/sql/copy.sql @@ -101,6 +101,13 @@ copy copytest to stdout json; copy copytest to stdout (format json); copy (select * from copytest) to stdout (format json); +-- keys are the query's column names, also when a scan does not project +copy (select a as x, b as y, c as z from copytest_order) to stdout (format json); +create temp table copytest_order2 (c int, b int, a int); +insert into copytest_order2 values (4, 5, 6); +copy (select * from copytest_order union all select * from copytest_order2) + to stdout (format json); + -- all of the following should yield error copy copytest to stdout (format json, delimiter '|'); copy copytest to stdout (format json, null '\N'); -- 2.37.1 (Apple Git-137.1)