From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: jian he <jian.universality@gmail.com>
Cc: Masahiko Sawada <sawada.mshk@gmail.com>
Cc: Joe Conway <mail@joeconway.com>
Cc: Daniel Verite <daniel@manitou-mail.org>
Cc: Andrew Dunstan <andrew@dunslane.net>
Cc: Davin Shearer <davin@apache.org>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: Emitting JSON to file using COPY TO
Date: Wed, 31 Jan 2024 14:26:28 +0100
Message-ID: <202401311326.zvfydnpkqnnd@alvherre.pgsql> (raw)
In-Reply-To: <CACJufxEh0QWok=XZTgFksSYSKLgkidud4cXJvJPxbTzVAsniPA@mail.gmail.com>
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.
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-general@postgresql.org
Cc: alvherre@alvh.no-ip.org, jian.universality@gmail.com, sawada.mshk@gmail.com, mail@joeconway.com, daniel@manitou-mail.org, andrew@dunslane.net, davin@apache.org, pgsql-hackers@postgresql.org
Subject: Re: Emitting JSON to file using COPY TO
In-Reply-To: <202401311326.zvfydnpkqnnd@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox