public inbox for [email protected]
help / color / mirror / Atom feedFrom: Xianbin Zhu <[email protected]>
To: [email protected]
Subject: [PATCH v1] psql: complete ALTER ROLE ... IN DATABASE ... RESET
Date: Sun, 29 Mar 2026 15:05:11 +0800
Message-ID: <CAD-rTHmcFSsG8N14G8BZeGSgY94v=N0NC-CHfnZegfYzEYnNQw@mail.gmail.com> (raw)
In-Reply-To: <CAD-rTHmBR8SW-p7Nc97HT-CEGr85WihdeTsrnLEiRGeK19nWAw@mail.gmail.com>
References: <CAD-rTHmBR8SW-p7Nc97HT-CEGr85WihdeTsrnLEiRGeK19nWAw@mail.gmail.com>
Hi hackers,
As discussed, here's a patch to add psql tab-completion support for:
ALTER ROLE/USER <name> IN DATABASE <db> RESET ...
Changes:
- Add completion path for "... IN DATABASE <db> RESET"
- Offer GUC names and ALL after RESET
- Add tab-completion test coverage in src/bin/psql/t/010_tab_completion.pl
Testing:
- make -j8
- make check (all tests passed in my environment)
Patch attached.
Thanks,
xianbinzhu
On Sun, Mar 29, 2026 at 2:50 PM Xianbin Zhu <[email protected]>
wrote:
> Hi hackers,
>
> I'd like to work on a small psql tab-completion improvement.
>
> Problem:
> psql currently has a missing completion path for:
> ALTER ROLE <role> IN DATABASE <db> RESET ...
>
> There is an in-code TODO marker for this case in
> src/bin/psql/tab-complete.in.c.
>
> Proposal:
> - Add completion support after "... IN DATABASE <db> RESET"
> - Reuse existing completion behavior/style used by ALTER ROLE ... RESET
> - Add regression coverage in src/bin/psql/t/010_tab_completion.pl
>
> Non-goals:
> - No backend behavior changes
> - No SQL grammar changes
>
> If this direction looks good, I can send a patch.
>
> Thanks,
> xianbinzhu
>
Attachments:
[application/octet-stream] 0001-psql-complete-ALTER-ROLE-.-IN-DATABASE-.-RESET.patch (2.4K, 3-0001-psql-complete-ALTER-ROLE-.-IN-DATABASE-.-RESET.patch)
download | inline diff:
From 6b80668783dca415932b1d8674c9e5fa7c6a3547 Mon Sep 17 00:00:00 2001
From: xianbinzhu <[email protected]>
Date: Sun, 29 Mar 2026 14:55:48 +0800
Subject: [PATCH] psql: complete ALTER ROLE ... IN DATABASE ... RESET
Signed-off-by: xianbinzhu <[email protected]>
---
src/bin/psql/t/010_tab_completion.pl | 12 ++++++++++++
src/bin/psql/tab-complete.in.c | 4 +++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/bin/psql/t/010_tab_completion.pl b/src/bin/psql/t/010_tab_completion.pl
index 1d2e5f5b92a..5e7b956a012 100644
--- a/src/bin/psql/t/010_tab_completion.pl
+++ b/src/bin/psql/t/010_tab_completion.pl
@@ -44,6 +44,7 @@ $node->safe_psql('postgres',
. "CREATE TABLE mytab246 (f1 int, f2 text);\n"
. "CREATE TABLE \"mixedName\" (f1 int, f2 text);\n"
. "CREATE TYPE enum1 AS ENUM ('foo', 'bar', 'baz', 'BLACK');\n"
+ . "CREATE ROLE tabcomp_role;\n"
. "CREATE PUBLICATION some_publication;\n");
# In a VPATH build, we'll be started in the source directory, but we want
@@ -228,6 +229,17 @@ check_completion(
clear_query();
+check_completion(
+ "ALTER ROLE tabcomp_role IN DATABASE post\t",
+ qr/postgres /,
+ "complete database name for ALTER ROLE ... IN DATABASE");
+check_completion(
+ "RESET clie\t",
+ qr/client_encoding /,
+ "complete GUC for ALTER ROLE ... IN DATABASE ... RESET");
+
+clear_query();
+
# check variant where we're completing a qualified name from a refname
# (this one also checks successful completion in a multiline command)
check_completion(
diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 523d3f39fc5..33728eda55c 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -2575,7 +2575,9 @@ match_previous_words(int pattern_id,
/* ALTER USER,ROLE <name> IN DATABASE <dbname> SET */
else if (Matches("ALTER", "USER|ROLE", MatchAny, "IN", "DATABASE", MatchAny, "SET"))
COMPLETE_WITH_QUERY(Query_for_list_of_set_vars);
- /* XXX missing support for ALTER ROLE <name> IN DATABASE <dbname> RESET */
+ /* ALTER USER,ROLE <name> IN DATABASE <dbname> RESET */
+ else if (Matches("ALTER", "USER|ROLE", MatchAny, "IN", "DATABASE", MatchAny, "RESET"))
+ COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_set_vars, "ALL");
/* ALTER USER,ROLE <name> RESET */
else if (Matches("ALTER", "USER|ROLE", MatchAny, "RESET"))
{
base-commit: 10e4d8aaf46fb46b8b78e026560b68af84a6495b
--
2.50.1 (Apple Git-155)
view thread (2+ messages)
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: [email protected]
Cc: [email protected], [email protected]
Subject: Re: [PATCH v1] psql: complete ALTER ROLE ... IN DATABASE ... RESET
In-Reply-To: <CAD-rTHmcFSsG8N14G8BZeGSgY94v=N0NC-CHfnZegfYzEYnNQw@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox