TAB completion for ALTER TABLE ... ALTER CONSTRAINT ... ENFORCED
Hi hackers!
While looking at [0]/messages/by-id/CACJufxFY=GkptsiH8X=VdyYAnNE_=u5j6WyDufTste6CuzRvnw@mail.gmail.com I noticed that current psql tab-complete lacks support for
ALTER TABLE ... ALTER CONSTRAINT ... [NOT] ENFORCED and
ALTER TABLE ... ALTER CONSTRAINT ... [NO] INHERIT
patterns.
I do understand that the psql tab complete feature is not designed for
full PostgreSQL's grammar support, yet this particular case is
relatively simple to support. So, should we add this feature?
Please let me know your thoughts.
[0]: /messages/by-id/CACJufxFY=GkptsiH8X=VdyYAnNE_=u5j6WyDufTste6CuzRvnw@mail.gmail.com
--
Best regards,
Kirill Reshke
Attachments:
v1-0001-Add-tab-completion-for-ALTER-TABLE-xxx-ALTER-CONT.patchapplication/octet-stream; name=v1-0001-Add-tab-completion-for-ALTER-TABLE-xxx-ALTER-CONT.patchDownload
From 5e7b2d04d99eb6e56ab219d17bb2903de81cd6e5 Mon Sep 17 00:00:00 2001
From: reshke <reshke@double.cloud>
Date: Mon, 11 Aug 2025 13:14:14 +0000
Subject: [PATCH v1] Add tab completion for ALTER TABLE xxx ALTER CONTRAINT ...
ENFORCED/INHERIT
---
src/bin/psql/tab-complete.in.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 1f2ca946fc5..5cc8e73feb1 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -2882,6 +2882,16 @@ match_previous_words(int pattern_id,
set_completion_reference(prev3_wd);
COMPLETE_WITH_SCHEMA_QUERY(Query_for_constraint_of_table);
}
+ /* if we have ALTER TABLE <sth> ALTER|DROP|RENAME CONSTRAINT <constraint>, provide [NOT] ENFORCED or [NO] INHERIT */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME", "CONSTRAINT", MatchAny))
+ {
+ COMPLETE_WITH("ENFORCED", "NOT ENFORCED", "NO INHERIT", "INHERIT");
+ }
+ /* if we have ALTER TABLE <sth> ALTER|DROP|RENAME CONSTRAINT <constraint> NO, provide INHERIT */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME", "CONSTRAINT", MatchAny, "NO"))
+ {
+ COMPLETE_WITH("INHERIT");
+ }
/* ALTER TABLE <sth> VALIDATE CONSTRAINT <non-validated constraint> */
else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT"))
{
--
2.43.0
On 11 Aug 2025, at 18:20, Kirill Reshke <reshkekirill@gmail.com> wrote:
Hi hackers!
While looking at [0] I noticed that current psql tab-complete lacks support for
ALTER TABLE ... ALTER CONSTRAINT ... [NOT] ENFORCED and
ALTER TABLE ... ALTER CONSTRAINT ... [NO] INHERIT
patterns.
Hi!
COMPLETE_WITH("ENFORCED", "NOT ENFORCED", "NO INHERIT", "INHERIT");
According to gram.y there might be DEFERRABLE and NOT DEFERRABLE, INITIALLY IMMEDIATE and INITIALLY DEFERRED (NOT VALID is acceptable by rules but not by the action)
Maybe we can add them too? If so, i attached v2 patch with this options added.
--
Best regards,
Roman Khapov
Attachments:
v2-0001-Add-tab-completion-for-ALTER-TABLE-xxx-ALTER-CONT.patchapplication/octet-stream; name=v2-0001-Add-tab-completion-for-ALTER-TABLE-xxx-ALTER-CONT.patch; x-unix-mode=0644Download
From eb4ef98a62a3263d5f928372faf590211084ff96 Mon Sep 17 00:00:00 2001
From: reshke <reshke@double.cloud>
Date: Mon, 11 Aug 2025 13:14:14 +0000
Subject: [PATCH v2] Add tab completion for ALTER TABLE xxx ALTER CONTRAINT ...
ENFORCED/INHERIT
Author: reshke <reshke@double.cloud>
Co-authored-by: Roman Khapov <r.khapov@ya.ru>
---
src/bin/psql/tab-complete.in.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index b1ff6f6cd94..488cbfb1933 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -2907,6 +2907,17 @@ match_previous_words(int pattern_id,
set_completion_reference(prev3_wd);
COMPLETE_WITH_SCHEMA_QUERY(Query_for_constraint_of_table);
}
+ /* if we have ALTER TABLE <sth> ALTER|DROP|RENAME CONSTRAINT <constraint>, provide [NOT] ENFORCED or [NO] INHERIT */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME", "CONSTRAINT", MatchAny))
+ {
+ COMPLETE_WITH("ENFORCED", "NOT ENFORCED", "NO INHERIT", "INHERIT", "DEFERRABLE",
+ "NOT DEFERRABLE", "INITIALLY IMMEDIATE", "INITIALLY DEFERRED");
+ }
+ /* if we have ALTER TABLE <sth> ALTER|DROP|RENAME CONSTRAINT <constraint> NO, provide INHERIT */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME", "CONSTRAINT", MatchAny, "NO"))
+ {
+ COMPLETE_WITH("INHERIT");
+ }
/* ALTER TABLE <sth> VALIDATE CONSTRAINT <non-validated constraint> */
else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT"))
{
--
2.50.1 (Apple Git-155)
On Mon, 29 Dec 2025 at 20:13, Roman Khapov <rkhapov@yandex-team.ru> wrote:
On 11 Aug 2025, at 18:20, Kirill Reshke <reshkekirill@gmail.com> wrote:
Hi hackers!
While looking at [0] I noticed that current psql tab-complete lacks support for
ALTER TABLE ... ALTER CONSTRAINT ... [NOT] ENFORCED and
ALTER TABLE ... ALTER CONSTRAINT ... [NO] INHERIT
patterns.
Hi!
COMPLETE_WITH("ENFORCED", "NOT ENFORCED", "NO INHERIT", "INHERIT");
According to gram.y there might be DEFERRABLE and NOT DEFERRABLE, INITIALLY IMMEDIATE and INITIALLY DEFERRED (NOT VALID is acceptable by rules but not by the action)
Maybe we can add them too? If so, i attached v2 patch with this options added.
--
Best regards,
Roman Khapov
Thanks. PFA v3 with commit msg polishing, and added support for NOT -
statement patterns.
}
+ /* if we have ALTER TABLE <sth> ALTER|DROP|RENAME CONSTRAINT
<constraint> NOT, provide DEFERRABLE or ENFORCED */
+ else if (Matches("ALTER", "TABLE", MatchAny,
"ALTER|DROP|RENAME", "CONSTRAINT", MatchAny, "NOT"))
+ {
+ COMPLETE_WITH("DEFERRABLE", "ENFORCED");
+ }
/* ALTER TABLE <sth> VALIDATE CONSTRAINT <non-validated constraint> */
else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT"))
{
--
Best regards,
Kirill Reshke
Attachments:
v3-0001-Add-tab-completion-for-ALTER-TABLE-xxx-ALTER-CONT.patchapplication/octet-stream; name=v3-0001-Add-tab-completion-for-ALTER-TABLE-xxx-ALTER-CONT.patchDownload
From 02cf5d1fd6bed3816249c9c4d967a7c96d6b5b9f Mon Sep 17 00:00:00 2001
From: reshke <reshke@double.cloud>
Date: Mon, 11 Aug 2025 13:14:14 +0000
Subject: [PATCH v3] Add tab completion for ALTER TABLE xxx ALTER CONTRAINT ...
patterns.
Support for changing contraint deferrability, inheritance and
enforceability
Author: reshke <reshke@double.cloud>
Co-authored-by: Roman Khapov <r.khapov@ya.ru>
---
src/bin/psql/tab-complete.in.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 75a101c6ab5..75cc42bc556 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -2907,6 +2907,22 @@ match_previous_words(int pattern_id,
set_completion_reference(prev3_wd);
COMPLETE_WITH_SCHEMA_QUERY(Query_for_constraint_of_table);
}
+ /* if we have ALTER TABLE <sth> ALTER|DROP|RENAME CONSTRAINT <constraint>, provide possible patterns */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME", "CONSTRAINT", MatchAny))
+ {
+ COMPLETE_WITH("ENFORCED", "NOT ENFORCED", "NO INHERIT", "INHERIT", "DEFERRABLE",
+ "NOT DEFERRABLE", "INITIALLY IMMEDIATE", "INITIALLY DEFERRED");
+ }
+ /* if we have ALTER TABLE <sth> ALTER|DROP|RENAME CONSTRAINT <constraint> NO, provide INHERIT */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME", "CONSTRAINT", MatchAny, "NO"))
+ {
+ COMPLETE_WITH("INHERIT");
+ }
+ /* if we have ALTER TABLE <sth> ALTER|DROP|RENAME CONSTRAINT <constraint> NOT, provide DEFERRABLE or ENFORCED */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME", "CONSTRAINT", MatchAny, "NOT"))
+ {
+ COMPLETE_WITH("DEFERRABLE", "ENFORCED");
+ }
/* ALTER TABLE <sth> VALIDATE CONSTRAINT <non-validated constraint> */
else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT"))
{
--
2.43.0