From: torikoshia <torikoshia@oss.nttdata.com>
To: Yugo Nagata <nagata@sraoss.co.jp>
Cc: sawada.mshk@gmail.com, Pgsql Hackers <pgsql-hackers@postgresql.org>
Subject: Re: Improve tab completion for COPY
Date: Tue, 10 Jun 2025 11:15:09 +0900
Message-ID: <ac23e824d1d602f113a89c91ee56fb23@oss.nttdata.com> (raw)
In-Reply-To: <20250603175801.d1fc50eefb178e5ca7312fd1@sraoss.co.jp>
References: <079e7a2c801f252ae8d522b772790ed7@oss.nttdata.com>
<20250507222318.421a6b6bfc311f4cdf07ebc0@sraoss.co.jp>
<CAD21AoDGvRZiHQoz1V+QQ4E3G9Yhzrq6_Siwi4iGtCmmP1hB2g@mail.gmail.com>
<20250508085335.77b8c480e96f032b87c2d8c3@sraoss.co.jp>
<0988d0a8c87c37ec8cb8d3643d9dc35a@oss.nttdata.com>
<20250603175801.d1fc50eefb178e5ca7312fd1@sraoss.co.jp>
On 2025-06-03 17:58, Yugo Nagata wrote:
> Thank you for updating the patch.
> It looks good and I confirmed that this works as expected.
Thanks for your review!
BTW this is a small patch, but it does two things:
(1) adds tab completion support for the REJECT_LIMIT option, which was
introduced in v18
(2) splits the tab completion logic between COPY FROM and COPY TO to
reflect their different options.
While maybe (2) should be postponed to v19 or later, I think it would be
better to include (1) in v18.
So I’ve split them into separate patches accordingly.
--
Atsushi Torikoshi
Seconded from NTT DATA GROUP CORPORATION to SRA OSS K.K.
Attachments:download all (2 files, .tar.gz)v3-0002-Improve-tab-completion-for-COPY-options.patch (text/x-diff, 3.2K) download
From 77b96ce98ca58d016fa984f2dbb890cc86855ebe Mon Sep 17 00:00:00 2001
From: Atsushi Torikoshi <torikoshia@oss.nttdata.com>
Date: Tue, 10 Jun 2025 10:55:24 +0900
Subject: [PATCH v3 2/2] 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.
---
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.cindex c0ba50019e..a1707100ac 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
@@ -3284,23 +3297,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", "REJECT_LIMIT");+ /* 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>) */
--
2.43.0
v3-0001-Add-tab-completion-for-COPY-REJECT_LIMIT-option.patch (text/x-diff, 1.1K) download
From b1f7076316e858a13f8bb1eabc7320938c613398 Mon Sep 17 00:00:00 2001
From: Atsushi Torikoshi <torikoshia@oss.nttdata.com>
Date: Tue, 10 Jun 2025 10:45:28 +0900
Subject: [PATCH v3 1/2] Add tab completion for COPY REJECT_LIMIT option
REJECT_LIMIT is a valid COPY option but was missing from tab
completion.
---
src/bin/psql/tab-complete.in.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.cindex ec65ab79fe..c0ba50019e 100644--- a/src/bin/psql/tab-complete.in.c+++ b/src/bin/psql/tab-complete.in.c@@ -3289,7 +3289,7 @@ match_previous_words(int pattern_id,
COMPLETE_WITH("FORMAT", "FREEZE", "DELIMITER", "NULL",
"HEADER", "QUOTE", "ESCAPE", "FORCE_QUOTE",
"FORCE_NOT_NULL", "FORCE_NULL", "ENCODING", "DEFAULT",
- "ON_ERROR", "LOG_VERBOSITY");+ "ON_ERROR", "LOG_VERBOSITY", "REJECT_LIMIT");
/* Complete COPY <sth> FROM|TO filename WITH (FORMAT */
else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(", "FORMAT"))
base-commit: 166b4f4560d68e2bcf0f82eb898ac5ee15147b82
--
2.43.0
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: torikoshia@oss.nttdata.com, nagata@sraoss.co.jp
Subject: Re: Improve tab completion for COPY
In-Reply-To: <ac23e824d1d602f113a89c91ee56fb23@oss.nttdata.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox