Re: Emitting JSON to file using COPY TO
jian he <jian.universality@gmail.com>
From: jian he <jian.universality@gmail.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Masahiko Sawada <sawada.mshk@gmail.com>, Joe Conway <mail@joeconway.com>, Daniel Verite <daniel@manitou-mail.org>,
Andrew Dunstan <andrew@dunslane.net>, Davin Shearer <davin@apache.org>,
PostgreSQL-development <pgsql-hackers@postgresql.org>, Junwang Zhao <zhjwpku@gmail.com>
Date: 2024-02-02T08:25:28Z
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, Jan 31, 2024 at 9:26 PM Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:
>
> On 2024-Jan-23, jian he wrote:
>
> > > + | FORMAT_LA copy_generic_opt_arg
> > > + {
> > > + $$ = makeDefElem("format", $2, @1);
> > > + }
> > > ;
> > >
> > > I think it's not necessary. "format" option is already handled in
> > > copy_generic_opt_elem.
> >
> > test it, I found out this part is necessary.
> > because a query with WITH like `copy (select 1) to stdout with
> > (format json, force_array false); ` will fail.
>
> Right, because "FORMAT JSON" is turned into FORMAT_LA JSON by parser.c
> (see base_yylex there). I'm not really sure but I think it might be
> better to make it "| FORMAT_LA JSON" instead of invoking the whole
> copy_generic_opt_arg syntax. Not because of performance, but just
> because it's much clearer what's going on.
>
sorry to bother you.
Now I didn't apply any patch, just at the master.
I don't know much about gram.y.
copy (select 1) to stdout with (format json1);
ERROR: COPY format "json1" not recognized
LINE 1: copy (select 1) to stdout with (format json1);
^
copy (select 1) to stdout with (format json);
ERROR: syntax error at or near "format"
LINE 1: copy (select 1) to stdout with (format json);
^
json is a keyword. Is it possible to escape it?
make `copy (select 1) to stdout with (format json)` error message the same as
`copy (select 1) to stdout with (format json1)`