Thanks for your comments!
On 2025-05-08 08:53, Yugo Nagata wrote:
On Wed, 7 May 2025 14:36:35 -0700
Masahiko Sawada <sawada.m...@gmail.com> wrote:
On Wed, May 7, 2025 at 6:23 AM Yugo Nagata <nag...@sraoss.co.jp>
wrote:
>
> On Wed, 7 May 2025 15:39:26 +0900
> torikoshia <torikos...@oss.nttdata.com> wrote:
>
> > Hi,
> >
> > I noticed that REJECT_LIMIT, an option available for COPY FROM, is not
> > currently supported in psql's tab completion.
> >
> > Additionally, some options are only valid for COPY FROM or COPY TO, i.e.
> > FREEZE, ON_ERROR, FORCE_QUOTE, but psql currently suggests them for both
> > COPY FROM and COPY TO.
> > As the number of COPY options continues to grow, I feel that having
> > irrelevant suggestions makes tab completion noisier.
>
> Indeed eliminating irrelevant suggestions would improve user experience,
+1
> but I think there is a drawback that it increases code maintenance for
> adding options used both in COPY FROM and TO. This might be trivial until
> the number of common options are small as now, though.
>
> Perhaps, the redundant code could be reduced by preparing a list (an array
> of const char*) containing common options part, then appending options
> specific to each mode using some function like kind of append_variable_names,
> and passing these lists to COMPLETE_WITH_LIST.
Or we can simply #define the common option list and #define two lists
for COPY TO and COPY FROM by concatenating the common option list,
like we do for ALTER PROCEDURE/ROUTINE/FUNCTION options.
+1
Agreed.
I think attached patch implemented the suggested way.
--
Regards,
--
Atsushi Torikoshi
Seconded from NTT DATA GROUP CORPORATION to SRA OSS K.K.
From 4e1ed3b2a4c7283ed3b7803c7071768ed5c22fc4 Mon Sep 17 00:00:00 2001
From: Atsushi Torikoshi <toriko...@sraoss.co.jp>
Date: Thu, 8 May 2025 21:11:20 +0900
Subject: [PATCH v2] Improve tab completion for COPY options
Currently, COPY FROM and TO share the same tab completion rules,
even though some options are only valid for one or the other.
This patch separates the tab completion rules for COPY FROM and
COPY TO to provide more accurate suggestions.
It also adds tab completion support for REJECT_LIMIT option,
which is valid only for COPY FROM.
---
src/bin/psql/tab-complete.in.c | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index c916b9299a..2111f72c91 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -1190,6 +1190,19 @@ Alter_procedure_options, "COST", "IMMUTABLE", "LEAKPROOF", "NOT LEAKPROOF", \
Alter_routine_options, "CALLED ON NULL INPUT", "RETURNS NULL ON NULL INPUT", \
"STRICT", "SUPPORT"
+/* COPY options shared between FROM and TO */
+#define Copy_common_options \
+"DELIMITER", "ENCODING", "ESCAPE", "FORMAT", "HEADER", "NULL", "QUOTE"
+
+/* COPY FROM options */
+#define Copy_from_options \
+Copy_common_options, "DEFAULT", "FORCE_NOT_NULL", "FORCE_NULL", "FREEZE", \
+"LOG_VERBOSITY", "ON_ERROR", "REJECT_LIMIT"
+
+/* COPY TO options */
+#define Copy_to_options \
+Copy_common_options, "FORCE_QUOTE"
+
/*
* These object types were introduced later than our support cutoff of
* server version 9.2. We use the VersionedQuery infrastructure so that
@@ -3278,23 +3291,24 @@ match_previous_words(int pattern_id,
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny))
COMPLETE_WITH("WITH (", "WHERE");
- /* Complete COPY <sth> FROM|TO filename WITH ( */
- else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "("))
- COMPLETE_WITH("FORMAT", "FREEZE", "DELIMITER", "NULL",
- "HEADER", "QUOTE", "ESCAPE", "FORCE_QUOTE",
- "FORCE_NOT_NULL", "FORCE_NULL", "ENCODING", "DEFAULT",
- "ON_ERROR", "LOG_VERBOSITY");
+ /* Complete COPY <sth> FROM filename WITH ( */
+ else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "("))
+ COMPLETE_WITH(Copy_from_options);
+
+ /* Complete COPY <sth> TO filename WITH ( */
+ else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny, "WITH", "("))
+ COMPLETE_WITH(Copy_to_options);
/* Complete COPY <sth> FROM|TO filename WITH (FORMAT */
else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(", "FORMAT"))
COMPLETE_WITH("binary", "csv", "text");
/* Complete COPY <sth> FROM filename WITH (ON_ERROR */
- else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(", "ON_ERROR"))
+ else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "(", "ON_ERROR"))
COMPLETE_WITH("stop", "ignore");
/* Complete COPY <sth> FROM filename WITH (LOG_VERBOSITY */
- else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(", "LOG_VERBOSITY"))
+ else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "(", "LOG_VERBOSITY"))
COMPLETE_WITH("silent", "default", "verbose");
/* Complete COPY <sth> FROM <sth> WITH (<options>) */
base-commit: 8fcc6487809efa5508a4b70049402236a53be84d
--
2.43.0