Re: Emitting JSON to file using COPY TO
David G. Johnston <david.g.johnston@gmail.com>
From: "David G. Johnston" <david.g.johnston@gmail.com>
To: Joe Conway <mail@joeconway.com>
Cc: Daniel Verite <daniel@manitou-mail.org>,
Andrew Dunstan <andrew@dunslane.net>, Davin Shearer <davin@apache.org>,
PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2023-12-06T23:28:06Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add option force_array for COPY JSON FORMAT
- 4c0390ac53b7 19 (unreleased) landed
-
json format for COPY TO
- 7dadd38cda95 19 (unreleased) landed
-
introduce CopyFormat, refactor CopyFormatOptions
- a2145605ee3d 19 (unreleased) landed
-
Doc: add IDs to copy.sgml's <varlistentry> and <refsect1>
- e4018f891dec 19 (unreleased) cited
On Wed, Dec 6, 2023 at 4:09 PM Joe Conway <mail@joeconway.com> wrote: > On 12/6/23 14:47, Joe Conway wrote: > > On 12/6/23 13:59, Daniel Verite wrote: > >> Andrew Dunstan wrote: > >> > >>> IMNSHO, we should produce either a single JSON > >>> document (the ARRAY case) or a series of JSON documents, one per row > >>> (the LINES case). > >> > >> "COPY Operations" in the doc says: > >> > >> " The backend sends a CopyOutResponse message to the frontend, followed > >> by zero or more CopyData messages (always one per row), followed by > >> CopyDone". > >> > >> In the ARRAY case, the first messages with the copyjsontest > >> regression test look like this (tshark output): > >> > >> PostgreSQL > >> Type: CopyOut response > >> Length: 13 > >> Format: Text (0) > >> Columns: 3 > >> Format: Text (0) > > > Anything receiving this and looking for a json array should know how to > > assemble the data correctly despite the extra CopyData messages. > > Hmm, maybe the real problem here is that Columns do not equal "3" for > the json mode case -- that should really say "1" I think, because the > row is not represented as 3 columns but rather 1 json object. > > Does that sound correct? > > Assuming yes, there is still maybe an issue that there are two more > "rows" that actual output rows (the "[" and the "]"), but maybe those > are less likely to cause some hazard? > > What is the limitation, if any, of introducing new type codes for these. n = 2..N for the different variants? Or even -1 for "raw text"? And document that columns and structural rows need to be determined out-of-band. Continuing to use 1 (text) for this non-csv data seems like a hack even if we can technically make it function. The semantics, especially for the array case, are completely discarded or wrong. David J.