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

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Neil Chen <carpenter(dot)nail(dot)cz(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 08:09:01
Message-ID: 6D883C50-5A1E-4CE4-9BB9-987632C46373@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Nov 25, 2026, at 15:04, Neil Chen <carpenter(dot)nail(dot)cz(at)gmail(dot)com> wrote:
>
> Hi Chao,
>
> Thanks for testing v2.

Thanks for updating the patch.

>
> 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 agree with these 3 criteria.

> 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?

I’m fine with leaving those issues for a separate discussion.

>
> [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/
> <v3-0001-psql-Complete-GRANTED-BY-in-GRANT-and-REVOKE.patch>

V3 looks good to me.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Koshi Shibagaki (Fujitsu) 2026-11-25 08:11:16 Re: [PATCH] Support casts from numeric to oid8
Previous Message Álvaro Herrera 2026-11-25 08:08:36 Re: remove unused shared WAL flush request