Re: Emitting JSON to file using COPY TO - Mailing list pgsql-hackers

From Joe Conway
Subject Re: Emitting JSON to file using COPY TO
Date
Msg-id 61818b31-4e7a-4d99-b08a-9e545dbf0038@joeconway.com
Whole thread Raw
In response to Re: Emitting JSON to file using COPY TO  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-hackers
On 12/7/23 09:11, David G. Johnston wrote:
> Those are all the same breakage though - if truly interpreted as data 
> rows the protocol is basically written such that the array format is not 
> supportable and only the lines format can be used.  Hence my “format 0 
> doesn’t work” comment for array output and we should explicitly add 
> format 2 where we explicitly decouple lines of output from rows of 
> data.  That said, it would seem in practice format 0 already decouples 
> them and so the current choice of the brackets on their own lines is 
> acceptable.
> 
> I’d prefer to keep them on their own line.

WFM ¯\_(ツ)_/¯

I am merely responding with options to the many people opining on the 
thread.

> I also don’t know why you introduced another level of object nesting 
> here.  That seems quite undesirable.

I didn't add anything. It is an artifact of the particular query I wrote 
in the copy to statement (I did "select ss from ss" instead of "select * 
from ss"), mea culpa.

This is what the latest patch, as written today, outputs:
8<----------------------
copy
(select 1, g.i from generate_series(1, 3) g(i))
to stdout (format json, force_array);
[
  {"?column?":1,"i":1}
,{"?column?":1,"i":2}
,{"?column?":1,"i":3}
]
8<----------------------

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




pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: UBSan pointer overflow in xlogreader.c
Next
From: "Euler Taveira"
Date:
Subject: Re: I’ve come across what I think is a bug