Re: Tab completion for CREATE SCHEMAAUTHORIZATION - Mailing list pgsql-hackers
From | Dagfinn Ilmari Mannsåker |
---|---|
Subject | Re: Tab completion for CREATE SCHEMAAUTHORIZATION |
Date | |
Msg-id | 87ildyqwks.fsf@wibble.ilmari.org Whole thread Raw |
In response to | Tab completion for CREATE SCHEMAAUTHORIZATION (ilmari@ilmari.org (Dagfinn Ilmari Mannsåker)) |
Responses |
Re: Tab completion for CREATE SCHEMAAUTHORIZATION
|
List | pgsql-hackers |
Michael Paquier <michael@paquier.xyz> writes: > On Wed, Aug 11, 2021 at 10:16:15AM +0900, Michael Paquier wrote: >> + else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION")) >> + COMPLETE_WITH_QUERY(Query_for_list_of_owner_roles); >> + else if (Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION")) >> + COMPLETE_WITH_QUERY(Query_for_list_of_owner_roles); >> + else if (Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION", MatchAny)) >> + COMPLETE_WITH("CREATE", "GRANT"); >> + else if (Matches("CREATE", "SCHEMA", MatchAny)) >> + COMPLETE_WITH("AUTHORIZATION", "CREATE", "GRANT"); >> Looks like you forgot the case "CREATE SCHEMA AUTHORIZATION MatchAny" >> that should be completed by GRANT and CREATE. > > This patch has been waiting on author for more than a couple of weeks, > so I have marked it as returned with feedback in the CF app. Please > feel free to resubmit if you are able to work more on that. Looks like I completely dropped the ball on this one, sorry. Here's a rebased patch which uses the new COMPLETE_WITH_QUERY_PLUS functionality added in commit 02b8048ba5dc36238f3e7c3c58c5946220298d71. - ilmari From 4c4833dfdd2bb01cd35715223433f961e5ec004c Mon Sep 17 00:00:00 2001 From: tanghy <tanghy.fnst@fujitsu.com> Date: Mon, 9 Aug 2021 18:47:12 +0100 Subject: [PATCH v2] Add tab completion for CREATE SCHEMA - AUTHORIZATION both in addition to and after a schema name - list of owner roles after AUTHORIZATION - CREATE and GRANT after any otherwise-complete command --- src/bin/psql/tab-complete.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 5825b2a195..222dd617a2 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1031,9 +1031,13 @@ static const SchemaQuery Query_for_trigger_of_table = { " FROM pg_catalog.pg_roles "\ " WHERE rolname LIKE '%s'" +/* add these to Query_for_list_of_roles in OWNER contexts */ +#define Keywords_for_list_of_owner_roles \ +"CURRENT_ROLE", "CURRENT_USER", "SESSION_USER" + /* add these to Query_for_list_of_roles in GRANT contexts */ #define Keywords_for_list_of_grant_roles \ -"PUBLIC", "CURRENT_ROLE", "CURRENT_USER", "SESSION_USER" +Keywords_for_list_of_owner_roles, "PUBLIC" #define Query_for_all_table_constraints \ "SELECT conname "\ @@ -3154,6 +3158,20 @@ psql_completion(const char *text, int start, int end) else if (TailMatches("AS", "ON", "SELECT|UPDATE|INSERT|DELETE", "TO")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); +/* CREATE SCHEMA [ <name> ] [ AUTHORIZATION ] */ + else if (Matches("CREATE", "SCHEMA")) + COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_schemas, + "AUTHORIZATION"); + else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION") || + Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION")) + COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, + Keywords_for_list_of_owner_roles); + else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION", MatchAny) || + Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION", MatchAny)) + COMPLETE_WITH("CREATE", "GRANT"); + else if (Matches("CREATE", "SCHEMA", MatchAny)) + COMPLETE_WITH("AUTHORIZATION", "CREATE", "GRANT"); + /* CREATE SEQUENCE --- is allowed inside CREATE SCHEMA, so use TailMatches */ else if (TailMatches("CREATE", "SEQUENCE", MatchAny) || TailMatches("CREATE", "TEMP|TEMPORARY", "SEQUENCE", MatchAny)) @@ -4263,9 +4281,7 @@ psql_completion(const char *text, int start, int end) /* OWNER TO - complete with available roles */ else if (TailMatches("OWNER", "TO")) COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, - "CURRENT_ROLE", - "CURRENT_USER", - "SESSION_USER"); + Keywords_for_list_of_owner_roles); /* ORDER BY */ else if (TailMatches("FROM", MatchAny, "ORDER")) -- 2.39.2
pgsql-hackers by date: