Re: Extend ALTER DEFAULT PRIVILEGES for large objects

Fujii Masao <masao.fujii@oss.nttdata.com>

From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Yugo Nagata <nagata@sraoss.co.jp>
Cc: Laurenz Albe <laurenz.albe@cybertec.at>, Nathan Bossart <nathandbossart@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers@postgresql.org
Date: 2025-07-10T04:23:47Z
Lists: pgsql-hackers

On 2025/07/10 10:30, Yugo Nagata wrote:
> You're right. I must have overlooked something. I think I saw "TO" being
> suggested after "FOREIGN SERVER" when no foreign servers were defined.
> 
> The attached patch still prevents "TO/FROM" from being suggested after
> "FOREIGN SERVER" in such cases.

Thanks for updating the patch!

Based on your patch, I'm thinking of simplifying the code like this:

-       else if (Matches("GRANT", MatchAnyN, "ON", MatchAny, MatchAny))
-               COMPLETE_WITH("TO");
-       else if (Matches("REVOKE", MatchAnyN, "ON", MatchAny, MatchAny))
-               COMPLETE_WITH("FROM");
+       else if (Matches("GRANT|REVOKE", MatchAnyN, "ON", MatchAny, MatchAny) &&
+                        !TailMatches("FOREIGN", "SERVER") && !TailMatches("LARGE", "OBJECT"))
+       {
+               if (Matches("GRANT", MatchAnyN, "ON", MatchAny, MatchAny))
+                       COMPLETE_WITH("TO");
+               else
+                       COMPLETE_WITH("FROM");
+       }


> But perhaps this corner case doesn't really
> need to be handled?

Probably I failed to get your point here. Could you clarify what you meant?

Regards,

-- 
Fujii Masao
NTT DATA Japan Corporation




Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. psql: Fix tab-completion after GRANT/REVOKE on LARGE OBJECT and FOREIGN SERVER.

  2. psql: Improve psql tab completion for GRANT/REVOKE on large objects.

  3. Extend ALTER DEFAULT PRIVILEGES to define default privileges for large objects.

  4. Convert tab-complete's long else-if chain to a switch statement.