public inbox for [email protected]  
help / color / mirror / Atom feed
[PROPOSAL] psql tab completion: support ALTER ROLE ... IN DATABASE ... RESET
2+ messages / 1 participants
[nested] [flat]

* [PROPOSAL] psql tab completion: support ALTER ROLE ... IN DATABASE ... RESET
@ 2026-03-29 06:50 Xianbin Zhu <[email protected]>
  2026-03-29 07:05 ` [PATCH v1] psql: complete ALTER ROLE ... IN DATABASE ... RESET Xianbin Zhu <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Xianbin Zhu @ 2026-03-29 06:50 UTC (permalink / raw)
  To: [email protected]

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


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* [PATCH v1] psql: complete ALTER ROLE ... IN DATABASE ... RESET
  2026-03-29 06:50 [PROPOSAL] psql tab completion: support ALTER ROLE ... IN DATABASE ... RESET Xianbin Zhu <[email protected]>
@ 2026-03-29 07:05 ` Xianbin Zhu <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Xianbin Zhu @ 2026-03-29 07:05 UTC (permalink / raw)
  To: [email protected]

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)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-03-29 07:05 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-03-29 06:50 [PROPOSAL] psql tab completion: support ALTER ROLE ... IN DATABASE ... RESET Xianbin Zhu <[email protected]>
2026-03-29 07:05 ` [PATCH v1] psql: complete ALTER ROLE ... IN DATABASE ... RESET Xianbin Zhu <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox