Re: Emitting JSON to file using COPY TO

From: Joe Conway <mail(at)joeconway(dot)com>
To: Daniel Verite <daniel(at)manitou-mail(dot)org>
Cc: 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: 2023-12-08 21:26:40
Message-ID: 8f98a14d-c5ee-49f8-8ea4-214405a3e291@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On 12/8/23 14:45, Daniel Verite wrote:
> Joe Conway wrote:
>
>> copyto_json.007.diff
>
> When the source has json fields with non-significant line feeds, the COPY
> output has these line feeds too, which makes the output incompatible
> with rule #2 at https://jsonlines.org ("2. Each Line is a Valid JSON
> Value").
>
> create table j(f json);
>
> insert into j values('{"a":1,
> "b":2
> }');
>
> copy j to stdout (format json);
>
> Result:
> {"f":{"a":1,
> "b":2
> }}
>
> Is that expected? copy.sgml in 007 doesn't describe the output
> in terms of lines so it's hard to tell from the doc.

The patch as-is just does the equivalent of row_to_json():
8<----------------------------
select row_to_json(j) from j;
row_to_json
--------------
{"f":{"a":1,+
"b":2 +
}}
(1 row)
8<----------------------------

So yeah, that is how it works today. I will take a look at what it would
take to fix it.

--
Joe Conway
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter J. Holzer 2023-12-08 22:31:50 Re: Store PDF files in PostgreDB
Previous Message Daniel Verite 2023-12-08 20:35:39 Re: Emitting JSON to file using COPY TO

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2023-12-08 22:15:54 Re: backtrace_on_internal_error
Previous Message Nathan Bossart 2023-12-08 20:37:08 Re: micro-optimizing json.c