On Wed, 11 Jun 2025 13:33:07 +0900 Fujii Masao <masao.fu...@oss.nttdata.com> wrote:
> > > On 2025/06/11 11:49, Yugo Nagata wrote: > > While looking at the thread [1], I've remembered this thread. > > The patches in this thread are partially v18-related, but include > > enhancement or fixes for existing feature, so should they be postponed > > to v19, or should be separated properly to v18 part and other? > > > > [1] > > https://www.postgresql.org/message-id/70372bdd-4399-4d5b-ab4f-6d4487a4911a%40oss.nttdata.com > > I see these patches more as enhancements to psql tab-completion, > rather than fixes for clear oversights in the original commit. > > For example, if tab-completion for ALTER DEFAULT PRIVILEGES had > completely missed LARGE OBJECTS, that would be an obvious oversight. > But these patches go beyond that kind of issue. > > That said, if others think it's appropriate to include them in v18 > for consistency or completeness, I'm fine with that. > > Regarding the 0002 patch: > > - 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)) > + { > + if (TailMatches("FOREIGN", "SERVER")) > + COMPLETE_WITH_QUERY(Query_for_list_of_servers); > + else if (!TailMatches("LARGE", "OBJECT")) > + { > + if (Matches("GRANT", MatchAnyN, "ON", MatchAny, > MatchAny)) > + COMPLETE_WITH("TO"); > + else > + COMPLETE_WITH("FROM"); > + } > + } > > Wouldn't this change break the case where "GRANT ... ON TABLE ... <TAB>" > is supposed to complete with "TO"? Sorry, I made a stupid mistake. > + else if (Matches("GRANT/REVOKE", MatchAnyN, "ON", MatchAny, MatchAny)) This should be "GRANT|REVOKE". I've attached update patches. (There is no change on 0001.) Best regards, Yugo Nagata -- Yugo Nagata <nag...@sraoss.co.jp>
>From 31558e92e0383ebd2be7d73d56675a723d8993ec Mon Sep 17 00:00:00 2001 From: Yugo Nagata <nag...@sraoss.co.jp> Date: Tue, 8 Apr 2025 12:15:45 +0900 Subject: [PATCH v2 2/2] psql: Some improvement of tab completion for GRANT/REVOKE This prevents to suggest TO or FROM just after LARGE OBJECT or FOREIGN SERVER because there should be largeobject id or server name at that place. Also, it allows to suggest list of foreign server names after FOREIGN SERVER. --- src/bin/psql/tab-complete.in.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index 42e23962bba..eebe7ac03ac 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -4573,10 +4573,18 @@ match_previous_words(int pattern_id, else if (Matches("ALTER", "DEFAULT", "PRIVILEGES", MatchAnyN, "TO", MatchAny)) COMPLETE_WITH("WITH GRANT OPTION"); /* Complete "GRANT/REVOKE ... ON * *" with TO/FROM */ - 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)) + { + if (TailMatches("FOREIGN", "SERVER")) + COMPLETE_WITH_QUERY(Query_for_list_of_servers); + else if (!TailMatches("LARGE", "OBJECT")) + { + if (Matches("GRANT", MatchAnyN, "ON", MatchAny, MatchAny)) + COMPLETE_WITH("TO"); + else + COMPLETE_WITH("FROM"); + } + } /* Complete "GRANT/REVOKE * ON ALL * IN SCHEMA *" with TO/FROM */ else if (TailMatches("GRANT|REVOKE", MatchAny, "ON", "ALL", MatchAny, "IN", "SCHEMA", MatchAny) || -- 2.43.0
>From 4c83dc42c9dfa9ee7cb9c3b92ca19a1ebf5bf2d9 Mon Sep 17 00:00:00 2001 From: Fujii Masao <fu...@postgresql.org> Date: Fri, 4 Apr 2025 10:51:20 +0900 Subject: [PATCH v2 1/2] 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 ec65ab79fec..42e23962bba 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -4608,6 +4608,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.43.0