[PATCH] Improve tab completion for ALTER TABLE on identity columns
Hi Hackers,
I noticed that psql has no tab completion around identity columns in
ALTER TABLE, so here's some patches for that.
In passing, I also added completion for ALTER SEQUECNE … START, which was
missing for some reason.
- ilmari
Attachments:
0001-psql-Add-tab-completion-for-ALTER-SEQUENCE-START.patchtext/x-diffDownload
From 4dad38d17e82b2efafe3666a0a92aa248cfc5e60 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Wed, 12 Oct 2022 14:17:12 +0100
Subject: [PATCH 1/4] =?UTF-8?q?psql:=20Add=20tab=20completion=20for=20ALTE?=
=?UTF-8?q?R=20SEQUENCE=20=E2=80=A6=20START=20=E2=80=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/bin/psql/tab-complete.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 584d9d5ae6..24a5f1f62b 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2104,7 +2104,7 @@ psql_completion(const char *text, int start, int end)
/* ALTER SEQUENCE <name> */
else if (Matches("ALTER", "SEQUENCE", MatchAny))
COMPLETE_WITH("AS", "INCREMENT", "MINVALUE", "MAXVALUE", "RESTART",
- "NO", "CACHE", "CYCLE", "SET", "OWNED BY",
+ "START", "NO", "CACHE", "CYCLE", "SET", "OWNED BY",
"OWNER TO", "RENAME TO");
/* ALTER SEQUENCE <name> AS */
else if (TailMatches("ALTER", "SEQUENCE", MatchAny, "AS"))
--
2.34.1
0002-psql-Add-tab-completion-for-ALTER-COLUMN-SET-GENERAT.patchtext/x-diffDownload
From 59b0ab0159ad941dbc39b22aabb07e82c814612d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Wed, 12 Oct 2022 14:03:52 +0100
Subject: [PATCH 2/4] =?UTF-8?q?psql:=20Add=20tab=20completion=20for=20ALTE?=
=?UTF-8?q?R=20COLUMN=20=E2=80=A6=20SET=20GENERATED=20=E2=80=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/bin/psql/tab-complete.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 24a5f1f62b..1d4f1fd794 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2381,7 +2381,7 @@ psql_completion(const char *text, int start, int end)
/* ALTER TABLE ALTER [COLUMN] <foo> SET */
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET") ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET"))
- COMPLETE_WITH("(", "COMPRESSION", "DEFAULT", "NOT NULL", "STATISTICS", "STORAGE");
+ COMPLETE_WITH("(", "COMPRESSION", "DEFAULT", "GENERATED", "NOT NULL", "STATISTICS", "STORAGE");
/* ALTER TABLE ALTER [COLUMN] <foo> SET ( */
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "(") ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "("))
@@ -2390,6 +2390,10 @@ psql_completion(const char *text, int start, int end)
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "COMPRESSION") ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "COMPRESSION"))
COMPLETE_WITH("DEFAULT", "PGLZ", "LZ4");
+ /* ALTER TABLE ALTER [COLUMN] <foo> SET GENERATED */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "GENERATED") ||
+ Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "GENERATED"))
+ COMPLETE_WITH("ALWAYS", "BY DEFAULT");
/* ALTER TABLE ALTER [COLUMN] <foo> SET STORAGE */
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "STORAGE") ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "STORAGE"))
--
2.34.1
0003-psql-Add-tab-completion-for-ALTER-COLUMN-SET-sequenc.patchtext/x-diffDownload
From 45c3d606f7d19fcee8223618ace7907b197401e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Wed, 12 Oct 2022 14:21:24 +0100
Subject: [PATCH 3/4] =?UTF-8?q?psql:=20Add=20tab=20completion=20for=20ALTE?=
=?UTF-8?q?R=20COLUMN=20=E2=80=A6=20SET=20<sequence=20option>?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/bin/psql/tab-complete.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 1d4f1fd794..009b6a7265 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2381,7 +2381,9 @@ psql_completion(const char *text, int start, int end)
/* ALTER TABLE ALTER [COLUMN] <foo> SET */
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET") ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET"))
- COMPLETE_WITH("(", "COMPRESSION", "DEFAULT", "GENERATED", "NOT NULL", "STATISTICS", "STORAGE");
+ COMPLETE_WITH("(", "COMPRESSION", "DEFAULT", "GENERATED", "NOT NULL", "STATISTICS", "STORAGE",
+ /* a subset of ALTER SEQUENCE options */
+ "INCREMENT", "MINVALUE", "MAXVALUE", "START", "NO", "CACHE", "CYCLE");
/* ALTER TABLE ALTER [COLUMN] <foo> SET ( */
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "(") ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "("))
@@ -2394,6 +2396,10 @@ psql_completion(const char *text, int start, int end)
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "GENERATED") ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "GENERATED"))
COMPLETE_WITH("ALWAYS", "BY DEFAULT");
+ /* ALTER TABLE ALTER [COLUMN] <foo> SET NO */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "NO") ||
+ Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "NO"))
+ COMPLETE_WITH("MINVALUE", "MAXVALUE", "CYCLE");
/* ALTER TABLE ALTER [COLUMN] <foo> SET STORAGE */
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "STORAGE") ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "STORAGE"))
--
2.34.1
0004-psql-Add-tab-completion-for-ALTER-COLUMN-ADD-GENERAT.patchtext/x-diffDownload
From 47661c1c5d866816af3b898fe5d20137f6497780 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Wed, 12 Oct 2022 15:07:13 +0100
Subject: [PATCH 4/4] =?UTF-8?q?psql:=20Add=20tab=20completion=20for=20ALTE?=
=?UTF-8?q?R=20COLUMN=20=E2=80=A6=20ADD=20GENERATED=20=E2=80=A6=20AS=20IDE?=
=?UTF-8?q?NTITY?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/bin/psql/tab-complete.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 009b6a7265..525bcf9d57 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2378,6 +2378,20 @@ psql_completion(const char *text, int start, int end)
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny) ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny))
COMPLETE_WITH("TYPE", "SET", "RESET", "RESTART", "ADD", "DROP");
+ /* ALTER TABLE ALTER [COLUMN] <foo> ADD */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "ADD") ||
+ Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "ADD"))
+ COMPLETE_WITH("GENERATED");
+ /* ALTER TABLE ALTER [COLUMN] <foo> ADD GENERATED */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "ADD", "GENERATED") ||
+ Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "ADD", "GENERATED"))
+ COMPLETE_WITH("ALWAYS", "BY DEFAULT");
+ /* ALTER TABLE ALTER [COLUMN] <foo> ADD GENERATED */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "ADD", "GENERATED", "ALWAYS") ||
+ Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "ADD", "GENERATED", "ALWAYS") ||
+ Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "ADD", "GENERATED", "BY", "DEFAULT") ||
+ Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "ADD", "GENERATED", "BY", "DEFAULT"))
+ COMPLETE_WITH("AS IDENTITY");
/* ALTER TABLE ALTER [COLUMN] <foo> SET */
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET") ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET"))
--
2.34.1
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> writes:
Hi Hackers,
I noticed that psql has no tab completion around identity columns in
ALTER TABLE, so here's some patches for that.
Added to the next commit fest:
https://commitfest.postgresql.org/40/3947/
- ilmari
Hi Hackers,
I noticed that psql has no tab completion around identity columns in
ALTER TABLE, so here's some patches for that.In passing, I also added completion for ALTER SEQUECNE … START, which was
missing for some reason.- ilmari
Hi ilmari
I've tested all 4 of your patches, and all of them seem to work as expected.
This is my first time reviewing a patch, so let's see if more experience
hackers has anything more to say about these patches, but at first they
seem correct to me.
--
Matheus Alcantara
On 14.10.22 16:31, Dagfinn Ilmari Mannsåker wrote:
I noticed that psql has no tab completion around identity columns in
ALTER TABLE, so here's some patches for that.Added to the next commit fest:
Committed.
On 26.10.22 00:45, Matheus Alcantara wrote:
I noticed that psql has no tab completion around identity columns in
ALTER TABLE, so here's some patches for that.In passing, I also added completion for ALTER SEQUECNE … START, which was
missing for some reason.
I've tested all 4 of your patches, and all of them seem to work as expected.
This is my first time reviewing a patch, so let's see if more experience
hackers has anything more to say about these patches, but at first they
seem correct to me.
This was sensible for a first review. Thanks for you help.
Peter Eisentraut <peter.eisentraut@enterprisedb.com> writes:
On 14.10.22 16:31, Dagfinn Ilmari Mannsåker wrote:
I noticed that psql has no tab completion around identity columns in
ALTER TABLE, so here's some patches for that.Added to the next commit fest:
https://commitfest.postgresql.org/40/3947/Committed.
Thanks!
- ilmari