On Fri, Jul 17, 2020 at 11:15 AM Michael Paquier <mich...@paquier.xyz> wrote: > > On Fri, Jul 10, 2020 at 09:58:28AM +0530, vignesh C wrote: > > Thanks for reviewing the patch. > > This changes is already present in the document, no need to make any > > changes as shown below: > > > > COPY table_name [ ( column_name [, ...] ) ] > > FROM { 'filename' | PROGRAM 'command' | STDIN } > > [ [ WITH ] ( option [, ...] ) ] > > [ WHERE condition ] > > Not completely actually. The page of psql for \copy does not mention > the optional where clause, and I think that it would be better to add > that for consistency (perhaps that's the point raised by Ahsan?). I > don't see much point in splitting the description of the meta-command > into two lines as we already mix stdin and stdout for example which > only apply to respectively "FROM" and "TO", so let's just append the > conditional where clause at its end. Attached is a patch doing so > that I intend to back-patch down to v12.
I would like to split into 2 lines similar to documentation of sql-copy which gives better readability, attaching a new patch in similar lines. > Coming back to your proposal, another thing is that with your patch > you recommend a syntax still present for compatibility reasons, but I > don't think that we should recommend it to the users anymore, giving > priority to the new grammar of the post-9.0 era. I would actually go > as far as removing BINARY from the completion when specified just > after COPY to simplify the code, and specify the list of available > options after typing "COPY ... WITH (FORMAT ", with "text", "csv" and > "binary". Adding completion for WHERE after COPY FROM is of course a > good idea. I agree with your comments, and have made a new patch accordingly. Thoughts? Regards, Vignesh EnterpriseDB: http://www.enterprisedb.com
From c7a7897f22aa3ad9b995a75a5fc4c933d0f9b383 Mon Sep 17 00:00:00 2001 From: Vignesh C <vignes...@gmail.com> Date: Fri, 17 Jul 2020 16:01:06 +0530 Subject: [PATCH 1/2] Corrected copy syntax. Split copy command into copy to & copy from and included the missing options. --- doc/src/sgml/ref/psql-ref.sgml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 42e862c..13179e8 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -982,9 +982,15 @@ testdb=> </varlistentry> <varlistentry id="app-psql-meta-commands-copy"> + <term><literal>\copy { <replaceable class="parameter">table</replaceable> [ ( <replaceable class="parameter">column_list</replaceable> ) ] } + <literal>from</literal> + { <replaceable class="parameter">'filename'</replaceable> | program <replaceable class="parameter">'command'</replaceable> | stdin | pstdin } + [ [ with ] ( <replaceable class="parameter">option</replaceable> [, ...] ) ] + [ where <replaceable class="parameter">condition</replaceable> ]</literal></term> + <term><literal>\copy { <replaceable class="parameter">table</replaceable> [ ( <replaceable class="parameter">column_list</replaceable> ) ] | ( <replaceable class="parameter">query</replaceable> ) } - { <literal>from</literal> | <literal>to</literal> } - { <replaceable class="parameter">'filename'</replaceable> | program <replaceable class="parameter">'command'</replaceable> | stdin | stdout | pstdin | pstdout } + <literal>to</literal> + { <replaceable class="parameter">'filename'</replaceable> | program <replaceable class="parameter">'command'</replaceable> | stdout | pstdout } [ [ with ] ( <replaceable class="parameter">option</replaceable> [, ...] ) ]</literal></term> <listitem> -- 1.8.3.1
From 4c56df45327aee448f1f55a7aef24b01f3f343b9 Mon Sep 17 00:00:00 2001 From: Vignesh C <vignes...@gmail.com> Date: Fri, 17 Jul 2020 17:06:15 +0530 Subject: [PATCH 2/2] Tab completion for copy statement. Tab completion for suggesting WITH, OPTIONS & WHERE was missing, this patch has the fix to suggest the same. I did not see any tests for tab completion, hence no tests were added. --- src/bin/psql/tab-complete.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index eb01885..f835758 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -2346,6 +2346,16 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH("BINARY", "DELIMITER", "NULL", "CSV", "ENCODING"); + /* Offer options after COPY <sth> FROM|TO filename WITH ( */ + else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(")) + COMPLETE_WITH("FORMAT", "FREEZE", "DELIMITER", "NULL", + "HEADER", "QUOTE", "ESCAPE", "FORCE_QUOTE", + "FORCE_NOT_NULL", "FORCE_NULL", "ENCODING"); + + /* Offer options after COPY <sth> FROM filename WITH options */ + else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", MatchAny)) + COMPLETE_WITH("WHERE"); + /* Offer options after COPY [BINARY] <sth> FROM|TO filename CSV */ else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "CSV") || Matches("COPY", "BINARY", MatchAny, "FROM|TO", MatchAny, "CSV")) -- 1.8.3.1