Skip to content

Commit f5a987c

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 86c539c commit f5a987c

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
@@ -1198,6 +1198,19 @@ Alter_procedure_options, "COST", "IMMUTABLE", "LEAKPROOF", "NOT LEAKPROOF", \
11981198
Alter_routine_options, "CALLED ON NULL INPUT", "RETURNS NULL ON NULL INPUT", \
11991199
"STRICT", "SUPPORT"
12001200

1201+
/* COPY options shared between FROM and TO */
1202+
#define Copy_common_options \
1203+
"DELIMITER", "ENCODING", "ESCAPE", "FORMAT", "HEADER", "NULL", "QUOTE"
1204+
1205+
/* COPY FROM options */
1206+
#define Copy_from_options \
1207+
Copy_common_options, "DEFAULT", "FORCE_NOT_NULL", "FORCE_NULL", "FREEZE", \
1208+
"LOG_VERBOSITY", "ON_ERROR", "REJECT_LIMIT"
1209+
1210+
/* COPY TO options */
1211+
#define Copy_to_options \
1212+
Copy_common_options, "FORCE_QUOTE"
1213+
12011214
/*
12021215
* These object types were introduced later than our support cutoff of
12031216
* server version 9.2. We use the VersionedQuery infrastructure so that
@@ -3299,23 +3312,24 @@ match_previous_words(int pattern_id,
32993312
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny))
33003313
COMPLETE_WITH("WITH (", "WHERE");
33013314

3302-
/* Complete COPY <sth> FROM|TO filename WITH ( */
3303-
else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "("))
3304-
COMPLETE_WITH("FORMAT", "FREEZE", "DELIMITER", "NULL",
3305-
"HEADER", "QUOTE", "ESCAPE", "FORCE_QUOTE",
3306-
"FORCE_NOT_NULL", "FORCE_NULL", "ENCODING", "DEFAULT",
3307-
"ON_ERROR", "LOG_VERBOSITY", "REJECT_LIMIT");
3315+
/* Complete COPY <sth> FROM filename WITH ( */
3316+
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "("))
3317+
COMPLETE_WITH(Copy_from_options);
3318+
3319+
/* Complete COPY <sth> TO filename WITH ( */
3320+
else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny, "WITH", "("))
3321+
COMPLETE_WITH(Copy_to_options);
33083322

33093323
/* Complete COPY <sth> FROM|TO filename WITH (FORMAT */
33103324
else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(", "FORMAT"))
33113325
COMPLETE_WITH("binary", "csv", "text");
33123326

33133327
/* Complete COPY <sth> FROM filename WITH (ON_ERROR */
3314-
else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(", "ON_ERROR"))
3328+
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "(", "ON_ERROR"))
33153329
COMPLETE_WITH("stop", "ignore");
33163330

33173331
/* Complete COPY <sth> FROM filename WITH (LOG_VERBOSITY */
3318-
else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(", "LOG_VERBOSITY"))
3332+
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "(", "LOG_VERBOSITY"))
33193333
COMPLETE_WITH("silent", "default", "verbose");
33203334

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

0 commit comments

Comments
 (0)