Skip to content

Commit d69836b

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 abb517d commit d69836b

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
@@ -1164,6 +1164,18 @@ Alter_procedure_options, "COST", "IMMUTABLE", "LEAKPROOF", "NOT LEAKPROOF", \
11641164
Alter_routine_options, "CALLED ON NULL INPUT", "RETURNS NULL ON NULL INPUT", \
11651165
"STRICT", "SUPPORT"
11661166

1167+
/* COPY options shared between FROM and TO */
1168+
#define Copy_common_options \
1169+
"DELIMITER", "ENCODING", "ESCAPE", "FORMAT", "HEADER", "NULL", "QUOTE"
1170+
1171+
/* COPY FROM options */
1172+
#define Copy_from_options \
1173+
Copy_common_options, "DEFAULT", "FORCE_NOT_NULL", "FORCE_NULL", "FREEZE"
1174+
1175+
/* COPY TO options */
1176+
#define Copy_to_options \
1177+
Copy_common_options, "FORCE_QUOTE"
1178+
11671179
/*
11681180
* These object types were introduced later than our support cutoff of
11691181
* server version 9.2. We use the VersionedQuery infrastructure so that
@@ -2854,11 +2866,13 @@ psql_completion(const char *text, int start, int end)
28542866
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny))
28552867
COMPLETE_WITH("WITH (", "WHERE");
28562868

2857-
/* Complete COPY <sth> FROM|TO filename WITH ( */
2858-
else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "("))
2859-
COMPLETE_WITH("FORMAT", "FREEZE", "DELIMITER", "NULL",
2860-
"HEADER", "QUOTE", "ESCAPE", "FORCE_QUOTE",
2861-
"FORCE_NOT_NULL", "FORCE_NULL", "ENCODING", "DEFAULT");
2869+
/* Complete COPY <sth> FROM filename WITH ( */
2870+
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "("))
2871+
COMPLETE_WITH(Copy_from_options);
2872+
2873+
/* Complete COPY <sth> TO filename WITH ( */
2874+
else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny, "WITH", "("))
2875+
COMPLETE_WITH(Copy_to_options);
28622876

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

0 commit comments

Comments
 (0)