Re: [PATCH] psql: Complete GRANTED BY in GRANT and REVOKE

From: Neil Chen <carpenter(dot)nail(dot)cz(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] psql: Complete GRANTED BY in GRANT and REVOKE
Date: 2026-11-25 07:04:31
Message-ID: CAA3qoJmWW29cpnZWWxPUkZ-V9HV=UnsGFJyny0OARrtvvszGmQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Chao,

Thanks for testing v2.

On Wed, Nov 25, 2026 at 10:30 AM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:

>
> After “grant”, type in a white space then tab, it prompts a list of
> options to choose, but I only expect “OPTION”.
>
>
Fixed it.
I also found the same problem in standalone REVOKE. The generic GRANT
rules offered roles and privileges after REVOKE GRANT and inserted TO
after REVOKE GRANT OPTION. These now offer OPTION FOR and FOR,
respectively. [1]

I also tightened the GRANTED BY matching for FROM r1,GROUP granted,
where granted is a role name and Tab shouldn't insert BY.

>
> If there is no whitespace between r1 and r2, it correctly prompts options,
> but a whitespace makes it to not work.
>
>
I tried this example with DROP TABLE. A space and Tab after
DROP TABLE t1,t2 give me CASCADE and RESTRICT. With DROP TABLE t1, t2,
I get neither. [2]

I tried a few more commands and found both wrong suggestions and
missing ones. The psql manual describes completion in many contexts,
and tab-complete.in.c says the aim is to cover common cases. [3] I'd
use three questions to decide what's worth fixing.

1. Can the suggested keyword go here? This is what prompted the
patch. After GRANT ... WITH GRANT OPTION, the generic GRANT rule
took OPTION for a role name and inserted TO. The fix that removed
FROM SERVER after CREATE PUBLICATION ... EXCEPT (...) is another
example. [4]

2. Is a common next step missing? After CREATE FOREIGN TABLE f (id int),
psql doesn't suggest the required SERVER clause. Once you type SERVER,
it offers server names. It would be worth seeing whether a simple rule
can fill that gap. TRUNCATE already offers the full RESTART IDENTITY
phrase. If you type RESTART by hand, Tab gives no suggestions, so
I'd leave that case alone. [5]

3. Do equivalent name lists get the same candidates? Once the list
can end, spacing after a comma shouldn't change the suggestions
for the next clause. A trailing comma still needs another name.
With REASSIGN OWNED BY r1, pressing Tab after a space currently
inserts TO too early.

I left the REVOKE spacing issue for discussion. It might make sense
to look at REVOKE, DROP TABLE, and REASSIGN OWNED together and see
whether they can handle lists the same way. Do you think the remaining
completion issues are worth discussing in separate threads?

[1] https://www.postgresql.org/docs/devel/sql-revoke.html
[2] https://www.postgresql.org/docs/devel/sql-droptable.html
[3]
https://www.postgresql.org/docs/devel/app-psql.html#APP-PSQL-COMMAND-LINE-EDITING
[4]
https://www.postgresql.org/message-id/E1wDbnx-001MS2-25%40gemulon.postgresql.org
[5] https://www.postgresql.org/docs/devel/sql-createforeigntable.html

Thanks,

--
Ze Chen (Neil)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachment Content-Type Size
v3-0001-psql-Complete-GRANTED-BY-in-GRANT-and-REVOKE.patch text/x-patch 5.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2026-11-25 07:24:30 Re: Ensure temporary files are unlinked on errors in pg_receivewal
Previous Message Amit Kapila 2026-11-25 06:54:16 Re: Proposal: Conflict log history table for Logical Replication