| 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-24 23:35:33 |
| Message-ID: | AB62D8AF-97F2-417F-ADB7-7F92863CD185@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> On Nov 20, 2026, at 16:57, Neil Chen <carpenter(dot)nail(dot)cz(at)gmail(dot)com> wrote:
>
> Hi hackers,
>
> While trying REVOKE ... GRANTED BY in PostgreSQL 19, I noticed that
> psql doesn't complete the clause or the grantor's name.
>
> I tried the corresponding GRANT and found that pressing Tab after
> a trailing space on this line inserts TO, making the statement invalid.
>
> GRANT SELECT ON t TO r WITH GRANT OPTION
>
> Before the patch, the generic GRANT rule treats the trailing GRANT
> OPTION as GRANT followed by a role name. The patch matches WITH
> GRANT OPTION first, so Tab inserts GRANTED BY. It also completes
> the clause and grantor name in both commands.
>
Hi Neil,
Thanks for the patch. I reviewed and tested this patch, and I have a few comments.
1
```
evantest=# revoke select ON all functions in schema public FROM chaol GRANTED BY chaol
```
After “GRANTED BY x”, [ CASCADE | RESTRICT ] can be specified, so we should support them as well.
2
```
+ /* GRANTED can itself be a role name, including after GROUP or a comma. */
+ else if (Matches("GRANT", MatchAnyN, "TO", MatchAnyExcept("GROUP"), "GRANTED") ||
+ Matches("REVOKE", MatchAnyN, "FROM", MatchAnyExcept("GROUP"), "GRANTED") ||
+ Matches("GRANT", MatchAnyN, "TO", MatchAny, "WITH",
+ "GRANT", "OPTION", "GRANTED") ||
+ Matches("GRANT", MatchAnyN, "TO", MatchAny, "WITH",
+ "ADMIN|INHERIT|SET", "OPTION|TRUE|FALSE", "GRANTED"))
+ {
+ if (!ends_with(prev2_wd, ','))
+ COMPLETE_WITH("BY");
+ }
```
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.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Manu | 2026-11-25 00:35:10 | Re: Allow progress tracking of sub-commands |
| Previous Message | Tomas Vondra | 2026-11-24 23:31:33 | Re: Parallel GIN, BRIN builds fail to maintain ii_BrokenHotChain |