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 02:29:29
Message-ID: 9F9C24CB-8353-4215-95FC-5694EE4425F2@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Nov 25, 2026, at 09:34, Neil Chen <carpenter(dot)nail(dot)cz(at)gmail(dot)com> wrote:
>
> Hi Chao,
>
> Thanks for the review.
>
> On Wed, Nov 25, 2026 at 7:36 AM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>
> After “GRANTED BY x”, [ CASCADE | RESTRICT ] can be specified, so we should support them as well.
>
>
> I added both after the grantor and alongside GRANTED BY after the
> grantee, since the grantor clause is optional.
>
> Is the check of comma really needed? At least for the latter 2 matches, prev2_wd would be OPTION|TRUE|FALSE, impossible to be comma.
>
> In the immediate next branch, the check on prev3_wd has a similar problem.
>
>
> You're right about the WITH forms. The GROUP and comma checks are
> now part of the grantee matches, where granted can be a role name,
> as in FROM alice, granted. After the full GRANTED BY, a single rule
> looks up the grantor for either command, even after a list. I removed
> the second comma check there. The lookup leaves out PUBLIC, which
> can't be a brantor.
>
> I kept keyword completion to one grantee word or one WITH option,
> following the existing GRANT completion rules.
> For role membership options, the name can be quoted, so the rule
> matches the value and uses a wildcard for the name.
>
> Attached is v2.
>
> Thanks,
>
> --
> Ze Chen (Neil)
> HighGo Software Co., Ltd.
> https://www.highgo.com/
> <v2-0001-psql-Complete-GRANTED-BY-in-GRANT-and-REVOKE.patch>

I just tested v2, and there are still something feels incorrect.

1
```
evantest=# grant select on t1 to r with grant
ALL pg_checkpoint pg_read_server_files SET
ALTER SYSTEM pg_create_subscription pg_signal_autovacuum_worker TEMPORARY
chaol pg_database_owner pg_signal_backend TRIGGER
CONNECT pg_execute_server_program pg_stat_scan_tables TRUNCATE
CREATE pg_maintain pg_use_reserved_connections UPDATE
DELETE pg_monitor pg_write_all_data USAGE
EXECUTE pg_read_all_data pg_write_server_files
INSERT pg_read_all_settings REFERENCES
MAINTAIN pg_read_all_stats SELECT
```

After “grant”, type in a white space then tab, it prompts a list of options to choose, but I only expect “OPTION”.

2
```
evantest=# revoke select on t1 from r1,r2
CASCADE GRANTED BY RESTRICT

evantest=# revoke select on t1 from r1, r2

```

If there is no whitespace between r1 and r2, it correctly prompts options, but a whitespace makes it to not work.

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 Tom Lane 2026-11-25 02:31:48 Re: passwordcheck: Make the user name check case-insensitive
Previous Message Anthony Sotolongo 2026-11-25 02:18:52 passwordcheck: Make the user name check case-insensitive