Skip to content

Commit 765a4c9

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 5d9e675 commit 765a4c9

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/bin/psql/tab-complete.in.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,19 @@ Alter_procedure_options, "COST", "IMMUTABLE", "LEAKPROOF", "NOT LEAKPROOF", \
11901190
Alter_routine_options, "CALLED ON NULL INPUT", "RETURNS NULL ON NULL INPUT", \
11911191
"STRICT", "SUPPORT"
11921192

1193+
/* COPY options shared between FROM and TO */
1194+
#define Copy_common_options \
1195+
"DELIMITER", "ENCODING", "ESCAPE", "FORMAT", "HEADER", "NULL", "QUOTE"
1196+
1197+
/* COPY FROM options */
1198+
#define Copy_from_options \
1199+
Copy_common_options, "DEFAULT", "FORCE_NOT_NULL", "FORCE_NULL", "FREEZE", \
1200+
"LOG_VERBOSITY", "ON_ERROR", "REJECT_LIMIT"
1201+
1202+
/* COPY TO options */
1203+
#define Copy_to_options \
1204+
Copy_common_options, "FORCE_QUOTE"
1205+
11931206
/*
11941207
* These object types were introduced later than our support cutoff of
11951208
* server version 9.2. We use the VersionedQuery infrastructure so that
@@ -3284,23 +3297,24 @@ match_previous_words(int pattern_id,
32843297
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny))
32853298
COMPLETE_WITH("WITH (", "WHERE");
32863299

3287-
/* Complete COPY <sth> FROM|TO filename WITH ( */
3288-
else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "("))
3289-
COMPLETE_WITH("FORMAT", "FREEZE", "DELIMITER", "NULL",
3290-
"HEADER", "QUOTE", "ESCAPE", "FORCE_QUOTE",
3291-
"FORCE_NOT_NULL", "FORCE_NULL", "ENCODING", "DEFAULT",
3292-
"ON_ERROR", "LOG_VERBOSITY", "REJECT_LIMIT");
3300+
/* Complete COPY <sth> FROM filename WITH ( */
3301+
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "("))
3302+
COMPLETE_WITH(Copy_from_options);
3303+
3304+
/* Complete COPY <sth> TO filename WITH ( */
3305+
else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny, "WITH", "("))
3306+
COMPLETE_WITH(Copy_to_options);
32933307

32943308
/* Complete COPY <sth> FROM|TO filename WITH (FORMAT */
32953309
else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(", "FORMAT"))
32963310
COMPLETE_WITH("binary", "csv", "text");
32973311

32983312
/* Complete COPY <sth> FROM filename WITH (ON_ERROR */
3299-
else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(", "ON_ERROR"))
3313+
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "(", "ON_ERROR"))
33003314
COMPLETE_WITH("stop", "ignore");
33013315

33023316
/* Complete COPY <sth> FROM filename WITH (LOG_VERBOSITY */
3303-
else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(", "LOG_VERBOSITY"))
3317+
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "(", "LOG_VERBOSITY"))
33043318
COMPLETE_WITH("silent", "default", "verbose");
33053319

33063320
/* Complete COPY <sth> FROM <sth> WITH (<options>) */

0 commit comments

Comments
 (0)