Re: Emitting JSON to file using COPY TO

From: Florents Tselai <florents(dot)tselai(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Junwang Zhao <zhjwpku(at)gmail(dot)com>, Joe Conway <mail(at)joeconway(dot)com>, "Andrey M(dot) Borodin" <x4mmm(at)yandex-team(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Daniel Verite <daniel(at)manitou-mail(dot)org>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Davin Shearer <davin(at)apache(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Emitting JSON to file using COPY TO
Date: 2026-02-03 16:40:49
Message-ID: CA+v5N43-F9-Wiktg_-+aqKJz+YiCNJMAh5ootDeTKkOJ=kiaHA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Wed, Jan 21, 2026 at 2:16 PM jian he <jian(dot)universality(at)gmail(dot)com> wrote:

> hi.
>
> rebase only.
>
> --
> jian
> https://www.enterprisedb.com/

I (and others I assume) would really like to see this in 19;
glancing at the thread above and in the test cases I see this is in good
shape for comitter review.
No?

If I were to add something it would be an example in copy.sgml
<para>
When the <literal>FORCE_ARRAY</literal> option is enabled,
the entire output is wrapped in a JSON array and individual rows are
separated by commas:
<programlisting>
COPY (SELECT id, name FROM users) TO STDOUT (FORMAT JSON, FORCE_ARRAY);
</programlisting>
<programlisting>
[
{"id": 1, "name": "Alice"}
,{"id": 2, "name": "Bob"}
,{"id": 3, "name": "Charlie"}
]
</programlisting>
</para>

Also, apologies if that has been discussed already,
is there a good reason why didn't we just go with a simple "WRAP_ARRAY" ?

In response to

Browse pgsql-general by date

  From Date Subject
Next Message yudhi s 2026-02-03 18:50:20 Re: Top -N Query performance issue and high CPU usage
Previous Message Adrian Klaver 2026-02-03 16:07:39 Re: Top -N Query performance issue and high CPU usage

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2026-02-03 16:52:52 Re: Skipping schema changes in publication
Previous Message Tom Lane 2026-02-03 16:33:20 Re: AIX support