Re: Emitting JSON to file using COPY TO

Andrew Dunstan <andrew@dunslane.net>

From: Andrew Dunstan <andrew@dunslane.net>
To: Joe Conway <mail@joeconway.com>, jian he <jian.universality@gmail.com>, Junwang Zhao <zhjwpku@gmail.com>
Cc: Florents Tselai <florents.tselai@gmail.com>, "Andrey M. Borodin" <x4mmm@yandex-team.ru>, Dean Rasheed <dean.a.rasheed@gmail.com>, Daniel Verite <daniel@manitou-mail.org>, Davin Shearer <davin@apache.org>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2026-03-05T20:49:55Z
Lists: pgsql-hackers, pgsql-general

Attachments

 >

On 2026-03-05 Th 1:06 PM, Joe Conway wrote:
>>
>>
>> Then I reworked the way this works. In order to support column lists 
>> with JSON output, we need to deal with individual columns instead of 
>> whole records. This involved quite a number of changes, as can be 
>> seen in patch 4. This involved exporting a new small function from 
>> json.c.
>>
>> The result is a lot cleaner, I believe, and in my benchmarking is 
>> faster by a factor of almost 2.
>
> Andrew,
>
> I don't see the actual patches. Did I miss it somewhere?



Nope. Bad hair day apparently.


cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Commits

  1. Add option force_array for COPY JSON FORMAT

  2. json format for COPY TO

  3. introduce CopyFormat, refactor CopyFormatOptions

  4. Doc: add IDs to copy.sgml's <varlistentry> and <refsect1>

  5. Refactor COPY TO to use format callback functions.