Skip to content

Commit 0514616

Browse files
Fix tab-completion for COPY and \copy options.
Commit c273d9d reworked tab-completion of COPY and \copy in psql and added support for completing options within WITH clauses. However, the same COPY options were suggested for both COPY TO and COPY FROM commands, even though some options are only valid for one or the other. This commit separates the COPY options for COPY FROM and COPY TO commands to provide more accurate auto-completion suggestions. Back-patch to v14 where tab-completion for COPY and \copy options within WITH clauses was first supported. Author: Atsushi Torikoshi <torikoshia@oss.nttdata.com> Reviewed-by: Yugo Nagata <nagata@sraoss.co.jp> Discussion: https://postgr.es/m/079e7a2c801f252ae8d522b772790ed7@oss.nttdata.com Backpatch-through: 14
1 parent 602c91c commit 0514616

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/bin/psql/tab-complete.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,18 @@ static const SchemaQuery Query_for_list_of_collations = {
10221022
" FROM pg_catalog.pg_cursors "\
10231023
" WHERE substring(pg_catalog.quote_ident(name),1,%d)='%s'"
10241024

1025+
/* COPY options shared between FROM and TO */
1026+
#define Copy_common_options \
1027+
"DELIMITER", "ENCODING", "ESCAPE", "FORMAT", "HEADER", "NULL", "QUOTE"
1028+
1029+
/* COPY FROM options */
1030+
#define Copy_from_options \
1031+
Copy_common_options, "FORCE_NOT_NULL", "FORCE_NULL", "FREEZE"
1032+
1033+
/* COPY TO options */
1034+
#define Copy_to_options \
1035+
Copy_common_options, "FORCE_QUOTE"
1036+
10251037
/*
10261038
* These object types were introduced later than our support cutoff of
10271039
* server version 7.4. We use the VersionedQuery infrastructure so that
@@ -2447,11 +2459,13 @@ psql_completion(const char *text, int start, int end)
24472459
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny))
24482460
COMPLETE_WITH("WITH (", "WHERE");
24492461

2450-
/* Complete COPY <sth> FROM|TO filename WITH ( */
2451-
else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "("))
2452-
COMPLETE_WITH("FORMAT", "FREEZE", "DELIMITER", "NULL",
2453-
"HEADER", "QUOTE", "ESCAPE", "FORCE_QUOTE",
2454-
"FORCE_NOT_NULL", "FORCE_NULL", "ENCODING");
2462+
/* Complete COPY <sth> FROM filename WITH ( */
2463+
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "("))
2464+
COMPLETE_WITH(Copy_from_options);
2465+
2466+
/* Complete COPY <sth> TO filename WITH ( */
2467+
else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny, "WITH", "("))
2468+
COMPLETE_WITH(Copy_to_options);
24552469

24562470
/* Complete COPY <sth> FROM|TO filename WITH (FORMAT */
24572471
else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(", "FORMAT"))

0 commit comments

Comments
 (0)