pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: ilmari@ilmari.org
To: pgsql-hackers@lists.postgresql.org
Subject: [PATCH] Tab completion for ALTER TABLE … ADD …
Date: Tue, 03 Aug 2021 12:48:38 +0100
Message-ID: <87bl6ehhpl.fsf@wibble.ilmari.org> (raw )
Hi Hackers,
The other day I noticed that there's no tab completion after ALTER TABLE
… ADD, so here's a patch. In addition to COLUMN and all the table
constraint types, it also completes with the list of unique indexes on
the table after ALTER TABLE … ADD … USING INDEX.
- ilmari
Attachments:
0001-Add-tab-completion-for-ALTER-TABLE-ADD.patch (text/x-diff, 3.5K) download
From 231cccd2e84ef6dc2bf41423979efc4e760c013e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Tue, 3 Aug 2021 12:23:07 +0100
Subject: [PATCH] =?UTF-8?q?Add=20tab=20completion=20for=20ALTER=20TABLE=20?=
=?UTF-8?q?=E2=80=A6=20ADD=20=E2=80=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Complte COLUMN and table constraint types, and list of indexes on the
table for ADD (UNQIUE|PRIMARY KEY) USING INDEX.
---
src/bin/psql/tab-complete.c | 44 +++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 064892bade..476a72908f 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -776,6 +776,10 @@ static const SchemaQuery Query_for_list_of_collations = {
" and pg_catalog.quote_ident(c1.relname)='%s'"\
" and pg_catalog.pg_table_is_visible(c2.oid)"
+#define Query_for_unique_index_of_table \
+Query_for_index_of_table \
+" and i.indisunique"
+
/* the silly-looking length condition is just to eat up the current word */
#define Query_for_constraint_of_table \
"SELECT pg_catalog.quote_ident(conname) "\
@@ -2023,6 +2027,46 @@ psql_completion(const char *text, int start, int end)
"OWNER TO", "SET", "VALIDATE CONSTRAINT",
"REPLICA IDENTITY", "ATTACH PARTITION",
"DETACH PARTITION", "FORCE ROW LEVEL SECURITY");
+ /* ALTER TABLE xxx ADD */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ADD"))
+ COMPLETE_WITH("COLUMN", "CONSTRAINT", "CHECK", "UNIQUE", "PRIMARY KEY",
+ "EXCLUDE", "FOREIGN KEY");
+ /* ALTER TABLE xxx ADD CONSTRAINT yyy */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny))
+ COMPLETE_WITH("CHECK", "UNIQUE", "PRIMARY KEY", "EXCLUDE", "FOREIGN KEY");
+ /* ALTER TABLE xxx ADD (CONSTRAINT yyy)? FOREIGN|PRIMARY */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "FOREIGN|PRIMARY") ||
+ Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, "FOREIGN|PRIMARY"))
+ COMPLETE_WITH("KEY");
+ /* ALTER TABLE xxx ADD (CONSTRAINT yyy)? (PRIMARY KEY|UNIQUE) */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "PRIMARY", "KEY") ||
+ Matches("ALTER", "TABLE", MatchAny, "ADD", "UNIQUE") ||
+ Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, "PRIMARY", "KEY") ||
+ Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, "UNIQUE"))
+ COMPLETE_WITH("(", "USING INDEX");
+ /* ALTER TABLE xxx ADD (CONSTRAINT yyy)? ... USING INDEX */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "PRIMARY", "KEY", "USING", "INDEX"))
+ {
+ completion_info_charp = prev6_wd;
+ COMPLETE_WITH_QUERY(Query_for_unique_index_of_table);
+ }
+ else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "UNIQUE", "USING", "INDEX"))
+ {
+ completion_info_charp = prev5_wd;
+ COMPLETE_WITH_QUERY(Query_for_unique_index_of_table);
+ }
+ else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny,
+ "PRIMARY", "KEY", "USING", "INDEX"))
+ {
+ completion_info_charp = prev8_wd;
+ COMPLETE_WITH_QUERY(Query_for_unique_index_of_table);
+ }
+ else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny,
+ "UNIQUE", "USING", "INDEX"))
+ {
+ completion_info_charp = prev7_wd;
+ COMPLETE_WITH_QUERY(Query_for_unique_index_of_table);
+ }
/* ALTER TABLE xxx ENABLE */
else if (Matches("ALTER", "TABLE", MatchAny, "ENABLE"))
COMPLETE_WITH("ALWAYS", "REPLICA", "ROW LEVEL SECURITY", "RULE",
--
2.30.2
view thread (8+ messages) latest in thread
Message-ID: <87bl6ehhpl.fsf@wibble.ilmari.org>
Permalink: ../87bl6ehhpl.fsf@wibble.ilmari.org/
Also on: postgresql.org/message-id/87bl6ehhpl.fsf@wibble.ilmari.org
copy link · copy postgr.es · copy git am
reply 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: ilmari@ilmari.org, pgsql-hackers@lists.postgresql.org
Subject: Re: [PATCH] Tab completion for ALTER TABLE … ADD …
In-Reply-To: <87bl6ehhpl.fsf@wibble.ilmari.org>
* 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