On 2025/04/04 0:21, Fujii Masao wrote:
Thanks for updating the patch!

If there are no objections, I'll proceed with committing it using the following 
commit log.

I've pushed the patch. Thanks!

While testing the feature, I noticed that psql doesn't complete
"ALTER DEFAULT PRIVILEGES GRANT/REVOKE ... ON LARGE OBJECTS" or
"GRANT/REVOKE ... ON LARGE OBJECT ..." with TO/FROM. The attached
patch adds tab-completion support for both cases.

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
From 02c1811af49b5f417af71b601cb60621640a14b4 Mon Sep 17 00:00:00 2001
From: Fujii Masao <fu...@postgresql.org>
Date: Fri, 4 Apr 2025 10:51:20 +0900
Subject: [PATCH v1] psql: Improve psql tab completion for GRANT/REVOKE on
 large objects.

This commit enhances psql's tab completion to support TO/FROM
after "GRANT/REVOKE ... ON LARGE OBJECT ...". Additionally,
since "ALTER DEFAULT PRIVILEGES" now supports large objects,
tab completion is also updated for "GRANT/REVOKE ... ON LARGE OBJECTS"
with TO/FROM.
---
 src/bin/psql/tab-complete.in.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index c916b9299a8..bdeb95fb3c8 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -4602,6 +4602,26 @@ match_previous_words(int pattern_id,
                        COMPLETE_WITH("FROM");
        }
 
+       /* Complete "GRANT/REVOKE * ON LARGE OBJECT *" with TO/FROM */
+       else if (TailMatches("GRANT|REVOKE", MatchAny, "ON", "LARGE", "OBJECT", 
MatchAny) ||
+                        TailMatches("REVOKE", "GRANT", "OPTION", "FOR", 
MatchAny, "ON", "LARGE", "OBJECT", MatchAny))
+       {
+               if (TailMatches("GRANT", MatchAny, MatchAny, MatchAny, 
MatchAny, MatchAny))
+                       COMPLETE_WITH("TO");
+               else
+                       COMPLETE_WITH("FROM");
+       }
+
+       /* Complete "GRANT/REVOKE * ON LARGE OBJECTS" with TO/FROM */
+       else if (TailMatches("GRANT|REVOKE", MatchAny, "ON", "LARGE", 
"OBJECTS") ||
+                        TailMatches("REVOKE", "GRANT", "OPTION", "FOR", 
MatchAny, "ON", "LARGE", "OBJECTS"))
+       {
+               if (TailMatches("GRANT", MatchAny, MatchAny, MatchAny, 
MatchAny))
+                       COMPLETE_WITH("TO");
+               else
+                       COMPLETE_WITH("FROM");
+       }
+
 /* GROUP BY */
        else if (TailMatches("FROM", MatchAny, "GROUP"))
                COMPLETE_WITH("BY");
-- 
2.48.1

Reply via email to