From: torikoshia <torikoshia@oss.nttdata.com>
To: Pgsql Hackers <pgsql-hackers@postgresql.org>
Subject: Improve tab completion for COPY
Date: Wed, 07 May 2025 15:39:26 +0900
Message-ID: <079e7a2c801f252ae8d522b772790ed7@oss.nttdata.com> (raw)
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.
Attached patch splits the tab completion rules between COPY FROM and
COPY TO, so that only the appropriate options are suggested for each.
What do you think?
Regards,
--
Atsushi Torikoshi
Seconded from NTT DATA GROUP CORPORATION to SRA OSS K.K.
Attachments:v1-0001-Improve-tab-completion-for-COPY-WITH-options.patch (text/x-diff, 2.5K) download
From 9efecf30f4c25f7c0457b679338f9cf4bbf03ec5 Mon Sep 17 00:00:00 2001
From: Atsushi Torikoshi <torikoshi@sraoss.co.jp>
Date: Wed, 7 May 2025 15:14:15 +0900
Subject: [PATCH v1] Improve tab completion for COPY WITH options
Split tab completion rules for COPY FROM and COPY TO to provide
accurate suggestions.
Also, add completion for the REJECT_LIMIT option, which is valid
only for COPY FROM.
---
src/bin/psql/tab-complete.in.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.cindex c916b9299a..d812fcab12 100644--- a/src/bin/psql/tab-complete.in.c+++ b/src/bin/psql/tab-complete.in.c@@ -3278,23 +3278,27 @@ 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",+ /* Complete COPY <sth> FROM filename WITH ( */+ else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "("))+ COMPLETE_WITH("FORMAT", "FREEZE", "DELIMITER", "NULL", "HEADER", "QUOTE", "ESCAPE",
"FORCE_NOT_NULL", "FORCE_NULL", "ENCODING", "DEFAULT",
- "ON_ERROR", "LOG_VERBOSITY");+ "ON_ERROR", "LOG_VERBOSITY", "REJECT_LIMIT");++ /* Complete COPY <sth> TO filename WITH ( */+ else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny, "WITH", "("))+ COMPLETE_WITH("FORMAT", "DELIMITER", "NULL", "HEADER", "QUOTE", "ESCAPE",+ "FORCE_QUOTE", "ENCODING");
/* 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: b560ce7884a32ba6409adab340b9732dcd210284
--
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
Subject: Re: Improve tab completion for COPY
In-Reply-To: <079e7a2c801f252ae8d522b772790ed7@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