Re: Emitting JSON to file using COPY TO

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Joe Conway <mail(at)joeconway(dot)com>, Daniel Verite <daniel(at)manitou-mail(dot)org>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Davin Shearer <davin(at)apache(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Junwang Zhao <zhjwpku(at)gmail(dot)com>
Subject: Re: Emitting JSON to file using COPY TO
Date: 2024-02-02 08:25:28
Message-ID: CACJufxHG9Cko8GTOQcx-8i7r1GugA=gJcwngvJzfLuGg9HRbjw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Wed, Jan 31, 2024 at 9:26 PM Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)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)`

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Laurenz Albe 2024-02-02 08:37:38 Re: Query running longer
Previous Message veem v 2024-02-02 04:44:09 Re: Query running longer

Browse pgsql-hackers by date

  From Date Subject
Next Message Corey Huinker 2024-02-02 08:33:08 Re: Statistics Import and Export
Previous Message Masahiko Sawada 2024-02-02 08:16:11 Re: Improve eviction algorithm in ReorderBuffer