From: Andrew Dunstan <andrew@dunslane.net>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add option force_array for COPY JSON FORMAT
Date: Fri, 20 Mar 2026 12:41:00 +0000
Message-ID: <E1w3Z9v-000dj6-1w@gemulon.postgresql.org> (raw)
Add option force_array for COPY JSON FORMAT
This adds the force_array option, which is available exclusively
when using COPY TO with the JSON format.
When enabled, this option wraps the output in a top-level JSON array
(enclosed in square brackets with comma-separated elements), making the
entire result a valid single JSON value. Without this option, the
default behavior is to output a stream of independent JSON objects.
Attempting to use this option with COPY FROM or with formats other than
JSON will raise an error.
Author: Joe Conway <mail@joeconway.com>
Author: jian he <jian.universality@gmail.com>
Reviewed-by: Junwang Zhao <zhjwpku@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Florents Tselai <florents.tselai@gmail.com>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://postgr.es/m/CALvfUkBxTYy5uWPFVwpk_7ii2zgT07t3d-yR_cy4sfrrLU%3Dkcg%40mail.gmail.com
Discussion: https://postgr.es/m/6a04628d-0d53-41d9-9e35-5a8dc302c34c@joeconway.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/4c0390ac53b745c2800f6aa3d9ee2515d6ab499b
Modified Files
--------------
doc/src/sgml/ref/copy.sgml | 30 ++++++++++++++++++++++++++++++
src/backend/commands/copy.c | 13 +++++++++++++
src/backend/commands/copyto.c | 38 ++++++++++++++++++++++++++++++++++++--
src/bin/psql/tab-complete.in.c | 2 +-
src/include/commands/copy.h | 1 +
src/test/regress/expected/copy.out | 37 +++++++++++++++++++++++++++++++++++++
src/test/regress/sql/copy.sql | 13 +++++++++++++
7 files changed, 131 insertions(+), 3 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: andrew@dunslane.net, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Add option force_array for COPY JSON FORMAT
In-Reply-To: <E1w3Z9v-000dj6-1w@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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