Added tab completion for the missing options in copy statement

Started by vignesh Cover 5 years ago11 messages
#1vignesh C
vignesh21@gmail.com
1 attachment(s)

Hi,

I found that tab completion for some parts of the copy statement was
missing. The Tab completion was missing for the following cases:
1) COPY [BINARY] <sth> FROM filename -> "BINARY", "DELIMITER", "NULL",
"CSV", "ENCODING", "WITH (", "WHERE" should be shown.
2) COPY [BINARY] <sth> TO filename -> "BINARY", "DELIMITER", "NULL",
"CSV", "ENCODING", "WITH (" should be shown.
3) COPY [BINARY] <sth> FROM filename WITH options -> "WHERE" should be shown.

I could not find any test cases for tab completion, hence no tests
were added. Attached a patch which has the fix for the same.
Thoughts?

Regards,
Vignesh
EnterpriseDB: http://www.enterprisedb.com

Attachments:

0001-Tab-completion-for-copy-statement.patchtext/x-patch; charset=US-ASCII; name=0001-Tab-completion-for-copy-statement.patchDownload
From f7eb10b548f43816cc578bae1d60bb9a739f989a Mon Sep 17 00:00:00 2001
From: Vignesh C <vignesh21@gmail.com>
Date: Thu, 25 Jun 2020 06:12:32 +0530
Subject: [PATCH] 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 | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index eb01885..0ffe31a 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2340,11 +2340,30 @@ psql_completion(const char *text, int start, int end)
 		completion_force_quote = false;
 		matches = rl_completion_matches(text, complete_from_files);
 	}
-	/* Offer options after COPY [BINARY] <sth> FROM|TO filename */
-	else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny) ||
-			 Matches("COPY", "BINARY", MatchAny, "FROM|TO", MatchAny))
+
+	/* Offer options after COPY [BINARY] <sth> FROM filename */
+	else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny) ||
+			 Matches("COPY", "BINARY", MatchAny, "FROM", MatchAny))
+		COMPLETE_WITH("BINARY", "DELIMITER", "NULL", "CSV",
+					  "ENCODING", "WITH (", "WHERE");
+
+	/* Offer options after COPY [BINARY] <sth> TO filename */
+	else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny) ||
+			 Matches("COPY", "BINARY", MatchAny, "TO", MatchAny))
 		COMPLETE_WITH("BINARY", "DELIMITER", "NULL", "CSV",
-					  "ENCODING");
+					  "ENCODING", "WITH (");
+
+	/* Offer options after COPY [BINARY] <sth> FROM|TO filename WITH ( */
+	else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(") ||
+			 Matches("COPY", "BINARY", 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 [BINARY] <sth> FROM filename WITH options */
+	else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", MatchAny) ||
+			 Matches("COPY", "BINARY", 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") ||
-- 
1.8.3.1

#2ahsan hadi
ahsan.hadi@gmail.com
In reply to: vignesh C (#1)
Re: Added tab completion for the missing options in copy statement

The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: not tested

Tested the tab complete for copy command, it provides the tab completion after providing the "TO|FROM filename With|Where". Does this require any doc change?

The new status of this patch is: Waiting on Author

#3vignesh C
vignesh21@gmail.com
In reply to: vignesh C (#1)
Re: Added tab completion for the missing options in copy statement

On Sat, Jun 27, 2020 at 6:52 AM vignesh C <vignesh21@gmail.com> wrote:

Hi,

I found that tab completion for some parts of the copy statement was
missing. The Tab completion was missing for the following cases:
1) COPY [BINARY] <sth> FROM filename -> "BINARY", "DELIMITER", "NULL",
"CSV", "ENCODING", "WITH (", "WHERE" should be shown.
2) COPY [BINARY] <sth> TO filename -> "BINARY", "DELIMITER", "NULL",
"CSV", "ENCODING", "WITH (" should be shown.
3) COPY [BINARY] <sth> FROM filename WITH options -> "WHERE" should be shown.

I could not find any test cases for tab completion, hence no tests
were added. Attached a patch which has the fix for the same.
Thoughts?

The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: not tested
Tested the tab complete for copy command, it provides the tab completion after providing the "TO|FROM filename With|Where". Does this require any doc change?

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 ]

Please have a look and let me know if you feel anything needs to be
added on top of it.

Regards,
Vignesh
EnterpriseDB: http://www.enterprisedb.com

#4Michael Paquier
michael@paquier.xyz
In reply to: ahsan hadi (#2)
Re: Added tab completion for the missing options in copy statement

On Tue, Jul 07, 2020 at 01:06:38PM +0000, ahsan hadi wrote:

Tested the tab complete for copy command, it provides the tab
completion after providing the "TO|FROM filename With|Where". Does
this require any doc change?

No documentation changes are required for that, as long as they match
the supported grammar.
--
Michael

#5Michael Paquier
michael@paquier.xyz
In reply to: vignesh C (#3)
1 attachment(s)
Re: Added tab completion for the missing options in copy statement

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.

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.
--
Michael

Attachments:

psql-copy-doc.patchtext/x-diff; charset=us-asciiDownload
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 42e862cf17..d9a2920910 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -985,7 +985,8 @@ testdb=&gt;
         <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 }
-        [ [ with ] ( <replaceable class="parameter">option</replaceable> [, ...] ) ]</literal></term>
+        [ [ with ] ( <replaceable class="parameter">option</replaceable> [, ...] ) ]
+        [ where <replaceable class="parameter">condition</replaceable> ]</literal></term>
 
         <listitem>
         <para>
#6vignesh C
vignesh21@gmail.com
In reply to: Michael Paquier (#5)
2 attachment(s)
Re: Added tab completion for the missing options in copy statement

On Fri, Jul 17, 2020 at 11:15 AM Michael Paquier <michael@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

Attachments:

0001-Corrected-copy-syntax.patchtext/x-patch; charset=US-ASCII; name=0001-Corrected-copy-syntax.patchDownload
From c7a7897f22aa3ad9b995a75a5fc4c933d0f9b383 Mon Sep 17 00:00:00 2001
From: Vignesh C <vignesh21@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=&gt;
       </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

0002-Tab-completion-for-copy-statement.patchtext/x-patch; charset=US-ASCII; name=0002-Tab-completion-for-copy-statement.patchDownload
From 4c56df45327aee448f1f55a7aef24b01f3f343b9 Mon Sep 17 00:00:00 2001
From: Vignesh C <vignesh21@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

#7Michael Paquier
michael@paquier.xyz
In reply to: vignesh C (#6)
1 attachment(s)
Re: Added tab completion for the missing options in copy statement

On Fri, Jul 17, 2020 at 05:28:51PM +0530, vignesh C wrote:

On Fri, Jul 17, 2020 at 11:15 AM Michael Paquier <michael@paquier.xyz> wrote:

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.

Fine by me. I have applied and back-patched this part down to 12.

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?

Nope, that's not what I meant. My point was to drop completely from
the completion the past grammar we are keeping around for
compatibility reasons, and just complete with the new grammar
documented at the top of the COPY page. This leads me to the
attached, which actually simplifies the code, adds more completion
patterns with the mixes of WHERE/WITH depending on if FROM or TO is
used, and at the end is less bug-prone if the grammar gets more
extended. I have also added some completion for "WITH (FORMAT" for
text, csv and binary.
--
Michael

Attachments:

psql-completion-copy.patchtext/x-diff; charset=us-asciiDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index eb018854a5..d5a47be422 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2316,19 +2316,14 @@ psql_completion(const char *text, int start, int end)
 	else if (Matches("COPY|\\copy"))
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables,
 								   " UNION ALL SELECT '('");
-	/* If we have COPY BINARY, complete with list of tables */
-	else if (Matches("COPY", "BINARY"))
-		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
-	/* If we have COPY (, complete it with legal commands */
+	/* Complete COPY ( with legal query commands */
 	else if (Matches("COPY|\\copy", "("))
 		COMPLETE_WITH("SELECT", "TABLE", "VALUES", "INSERT", "UPDATE", "DELETE", "WITH");
-	/* If we have COPY [BINARY] <sth>, complete it with "TO" or "FROM" */
-	else if (Matches("COPY|\\copy", MatchAny) ||
-			 Matches("COPY", "BINARY", MatchAny))
+	/* Complete COPY <sth> */
+	else if (Matches("COPY|\\copy", MatchAny))
 		COMPLETE_WITH("FROM", "TO");
-	/* If we have COPY [BINARY] <sth> FROM|TO, complete with filename */
-	else if (Matches("COPY", MatchAny, "FROM|TO") ||
-			 Matches("COPY", "BINARY", MatchAny, "FROM|TO"))
+	/* Complete COPY <sth> FROM|TO with filename */
+	else if (Matches("COPY", MatchAny, "FROM|TO"))
 	{
 		completion_charp = "";
 		completion_force_quote = true;	/* COPY requires quoted filename */
@@ -2340,17 +2335,28 @@ psql_completion(const char *text, int start, int end)
 		completion_force_quote = false;
 		matches = rl_completion_matches(text, complete_from_files);
 	}
-	/* Offer options after COPY [BINARY] <sth> FROM|TO filename */
-	else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny) ||
-			 Matches("COPY", "BINARY", MatchAny, "FROM|TO", MatchAny))
-		COMPLETE_WITH("BINARY", "DELIMITER", "NULL", "CSV",
-					  "ENCODING");
 
-	/* 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"))
-		COMPLETE_WITH("HEADER", "QUOTE", "ESCAPE", "FORCE QUOTE",
-					  "FORCE NOT NULL");
+	/* Complete COPY <smt> TO <smt> */
+	else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny))
+		COMPLETE_WITH("WITH (");
+
+	/* Complete COPY <smt> FROM <smt> */
+	else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny))
+		COMPLETE_WITH("WITH (", "WHERE");
+
+	/* Complete 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");
+
+	/* Complete COPY <sth> FROM|TO filename WITH (FORMAT */
+	else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(", "FORMAT"))
+		COMPLETE_WITH("binary", "csv", "text");
+
+	/* Complete COPY <smt> FROM <smt> WITH (<options>) */
+	else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", MatchAny))
+		COMPLETE_WITH("WHERE");
 
 	/* CREATE ACCESS METHOD */
 	/* Complete "CREATE ACCESS METHOD <name>" */
#8vignesh C
vignesh21@gmail.com
In reply to: Michael Paquier (#7)
Re: Added tab completion for the missing options in copy statement

On Sat, Jul 18, 2020 at 8:08 AM Michael Paquier <michael@paquier.xyz> wrote:

On Fri, Jul 17, 2020 at 05:28:51PM +0530, vignesh C wrote:

On Fri, Jul 17, 2020 at 11:15 AM Michael Paquier <michael@paquier.xyz> wrote:

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.

Fine by me. I have applied and back-patched this part down to 12.

Thanks for pushing the patch.

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?

Nope, that's not what I meant. My point was to drop completely from
the completion the past grammar we are keeping around for
compatibility reasons, and just complete with the new grammar
documented at the top of the COPY page. This leads me to the
attached, which actually simplifies the code, adds more completion
patterns with the mixes of WHERE/WITH depending on if FROM or TO is
used, and at the end is less bug-prone if the grammar gets more
extended. I have also added some completion for "WITH (FORMAT" for
text, csv and binary.

This version of patch looks good, patch applies, make check & make
check-world passes.
This is not part of the new changes, this change already exists, I had
one small clarification on the below code:
/* Complete COPY ( with legal query commands */
else if (Matches("COPY|\\copy", "("))
COMPLETE_WITH("SELECT", "TABLE", "VALUES", "INSERT", "UPDATE",
"DELETE", "WITH");

Can we specify Insert/Update or delete with copy?
When I tried few scenarios I was getting the following error:
ERROR: COPY query must have a RETURNING clause

I might be missing some scenarios, just wanted to confirm if this is
kept intentionally.

Regards,
Vignesh
EnterpriseDB: http://www.enterprisedb.com

#9Michael Paquier
michael@paquier.xyz
In reply to: vignesh C (#8)
Re: Added tab completion for the missing options in copy statement

On Sat, Jul 18, 2020 at 04:12:02PM +0530, vignesh C wrote:

Can we specify Insert/Update or delete with copy?
When I tried few scenarios I was getting the following error:
ERROR: COPY query must have a RETURNING clause

I might be missing some scenarios, just wanted to confirm if this is
kept intentionally.

This error message says it all, this is supported for a DML that
includes a RETURNING clause:
=# create table aa (a int);
CREATE TABLE
=# copy (insert into aa values (generate_series(2,5)) returning a)
to '/tmp/data.txt';
COPY 4
=# \! cat /tmp/data.txt
2
3
4
5

Thanks,
--
Michael

#10vignesh C
vignesh21@gmail.com
In reply to: Michael Paquier (#9)
Re: Added tab completion for the missing options in copy statement

On Sat, Jul 18, 2020 at 4:36 PM Michael Paquier <michael@paquier.xyz> wrote:

On Sat, Jul 18, 2020 at 04:12:02PM +0530, vignesh C wrote:

Can we specify Insert/Update or delete with copy?
When I tried few scenarios I was getting the following error:
ERROR: COPY query must have a RETURNING clause

I might be missing some scenarios, just wanted to confirm if this is
kept intentionally.

This error message says it all, this is supported for a DML that
includes a RETURNING clause:
=# create table aa (a int);
CREATE TABLE
=# copy (insert into aa values (generate_series(2,5)) returning a)
to '/tmp/data.txt';
COPY 4
=# \! cat /tmp/data.txt
2
3
4
5

Thanks Michael for the clarification, the patch looks fine to me.

Regards,
Vignesh
EnterpriseDB: http://www.enterprisedb.com

#11Michael Paquier
michael@paquier.xyz
In reply to: vignesh C (#10)
Re: Added tab completion for the missing options in copy statement

On Sat, Jul 18, 2020 at 04:49:23PM +0530, vignesh C wrote:

Thanks Michael for the clarification, the patch looks fine to me.

Thanks for the confirmation, committed.
--
Michael