question about docs on copy command

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

question about docs on copy command

Platon Pronko
Hi!

I'm having a little trouble with docs of COPY command: https://www.postgresql.org/docs/11/sql-copy.html

Excerpt from synopsis:

> COPY { table_name [ ( column_name [, ...] ) ] | ( query ) }
>     TO { 'filename' | PROGRAM 'command' | STDOUT }
>     [ [ WITH ] ( option [, ...] ) ]
>
> where option can be one of:
>
>     FORMAT format_name

This led me to beleive that the following command should be valid:

copy (select 1) to stdout with format csv;

However, the error is shown:

> ERROR:  syntax error at or near "format"
> LINE 1: copy (select 1) to stdout with format csv;
>                                        ^

This command executes normally:

copy (select 1) to stdout with csv;

Am I missing something, or maybe the docs need a slight correction?

Best regards,
Platon Pronko


Reply | Threaded
Open this post in threaded view
|

RE: question about docs on copy command

David Raymond
It also appears to be disliking the comma for including more than one option. So something's definitely up with that. But I can't tell you if it's a bug with the program or with the documentation, so hopefully someone else can chime in on that.

(On 11.5 by the way)
mnr=> copy (select 1, 'With space', null) to stdout with null 'NuLL';
1       With space      NuLL
mnr=> copy (select 1, 'With space', null) to stdout with delimiter '|';
1|With space|\N
mnr=> copy (select 1, 'With space', null) to stdout with delimiter '|', null 'NuLL';
ERROR:  syntax error at or near ","
LINE 1: ..., 'With space', null) to stdout with delimiter '|', null 'Nu...
                                                             ^



-----Original Message-----
From: Platon Pronko <[hidden email]>
Sent: Friday, September 6, 2019 3:47 AM
To: [hidden email]
Subject: question about docs on copy command

Hi!

I'm having a little trouble with docs of COPY command: https://www.postgresql.org/docs/11/sql-copy.html

Excerpt from synopsis:

> COPY { table_name [ ( column_name [, ...] ) ] | ( query ) }
>     TO { 'filename' | PROGRAM 'command' | STDOUT }
>     [ [ WITH ] ( option [, ...] ) ]
>
> where option can be one of:
>
>     FORMAT format_name

This led me to beleive that the following command should be valid:

copy (select 1) to stdout with format csv;

However, the error is shown:

> ERROR:  syntax error at or near "format"
> LINE 1: copy (select 1) to stdout with format csv;
>                                        ^

This command executes normally:

copy (select 1) to stdout with csv;

Am I missing something, or maybe the docs need a slight correction?

Best regards,
Platon Pronko


Reply | Threaded
Open this post in threaded view
|

Re: question about docs on copy command

Tom Lane-2
In reply to this post by Platon Pronko
Platon Pronko <[hidden email]> writes:
> I'm having a little trouble with docs of COPY command: https://www.postgresql.org/docs/11/sql-copy.html

> Excerpt from synopsis:

>> COPY { table_name [ ( column_name [, ...] ) ] | ( query ) }
>> TO { 'filename' | PROGRAM 'command' | STDOUT }
>> [ [ WITH ] ( option [, ...] ) ]
>>
>> where option can be one of:
>>
>> FORMAT format_name

> This led me to beleive that the following command should be valid:

> copy (select 1) to stdout with format csv;

You missed the parentheses.  This works:

regression=# copy (select 1) to stdout with (format csv);
1

It does require a bit of attention to tell the metacharacters (braces
and square brackets) from the literal punctuation :-(

> This command executes normally:
> copy (select 1) to stdout with csv;

IIRC, that's valid per the "old syntax" described near the end of the
page.  The new syntax uses parens.

                        regards, tom lane


Reply | Threaded
Open this post in threaded view
|

Re: question about docs on copy command

Platon Pronko
Indeed, my eyes completely ignored all the punctuation or pattern characters. Thank you!

Best regards,
Platon Pronko

On 2019-09-06 17:01, Tom Lane wrote:

> Platon Pronko <[hidden email]> writes:
>> I'm having a little trouble with docs of COPY command: https://www.postgresql.org/docs/11/sql-copy.html
>
>> Excerpt from synopsis:
>
>>> COPY { table_name [ ( column_name [, ...] ) ] | ( query ) }
>>> TO { 'filename' | PROGRAM 'command' | STDOUT }
>>> [ [ WITH ] ( option [, ...] ) ]
>>>
>>> where option can be one of:
>>>
>>> FORMAT format_name
>
>> This led me to beleive that the following command should be valid:
>
>> copy (select 1) to stdout with format csv;
>
> You missed the parentheses.  This works:
>
> regression=# copy (select 1) to stdout with (format csv);
> 1
>
> It does require a bit of attention to tell the metacharacters (braces
> and square brackets) from the literal punctuation :-(
>
>> This command executes normally:
>> copy (select 1) to stdout with csv;
>
> IIRC, that's valid per the "old syntax" described near the end of the
> page.  The new syntax uses parens.
>
> regards, tom lane
>