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
From f7eb10b548f43816cc578bae1d60bb9a739f989a Mon Sep 17 00:00:00 2001
From: Vignesh C <[email protected]>
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