From: ilmari@ilmari.org
To: pgsql-hackers@lists.postgresql.org
Subject: Re: Tab completion for CREATE SCHEMAAUTHORIZATION
Date: Sat, 07 Aug 2021 22:09:19 +0100
Message-ID: <874kc1gdxc.fsf@wibble.ilmari.org> (raw)
In-Reply-To: <87wnprhlsl.fsf@wibble.ilmari.org>
References: <8735snihmz.fsf@wibble.ilmari.org>
<87wnprhlsl.fsf@wibble.ilmari.org>
ilmari@ilmari.org (Dagfinn Ilmari Mannsåker) writes:
> ilmari@ilmari.org (Dagfinn Ilmari Mannsåker) writes:
>
>> Hi Hackers,
>>
>> I just noticed there's no tab completion for CREATE SCHEMA
>> AUTHORIZATION, nor for anything after CREATE SCHEMA <name>.
>>
>> Please find attached a patch that adds this.
>
> Added to the 2021-09 commit fest: https://commitfest.postgresql.org/34/3252/
Here's an updated version that also reduces the duplication between the
various role list queries.
- ilmari
Attachments:v2-0001-Add-tab-completion-for-CREATE-SCHEMA.patch (text/x-diff, 2.5K) download
From 52c1fe9900543253510b64e58de24f920d8b0dc5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Fri, 9 Jul 2021 17:15:00 +0100
Subject: [PATCH v2] Add tab completion for CREATE SCHEMA
In passing, reduce duplication between the various role list queries
---
src/bin/psql/tab-complete.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.cindex 064892bade..adddd45f59 100644--- a/src/bin/psql/tab-complete.c+++ b/src/bin/psql/tab-complete.c@@ -758,15 +758,16 @@ static const SchemaQuery Query_for_list_of_collations = {
" FROM pg_catalog.pg_roles "\
" WHERE substring(pg_catalog.quote_ident(rolname),1,%d)='%s'"
-#define Query_for_list_of_grant_roles \-" SELECT pg_catalog.quote_ident(rolname) "\-" FROM pg_catalog.pg_roles "\-" WHERE substring(pg_catalog.quote_ident(rolname),1,%d)='%s'"\-" UNION ALL SELECT 'PUBLIC'"\-" UNION ALL SELECT 'CURRENT_ROLE'"\+#define Query_for_list_of_schema_roles \+Query_for_list_of_roles \
" UNION ALL SELECT 'CURRENT_USER'"\
" UNION ALL SELECT 'SESSION_USER'"
+#define Query_for_list_of_grant_roles \+Query_for_list_of_schema_roles \+" UNION ALL SELECT 'PUBLIC'"\+" UNION ALL SELECT 'CURRENT_ROLE'"+
/* the silly-looking length condition is just to eat up the current word */
#define Query_for_index_of_table \
"SELECT pg_catalog.quote_ident(c2.relname) "\
@@ -2675,6 +2676,19 @@ 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, NULL);
+/* CREATE SCHEMA [ <name> ] [ AUTHORIZATION ] */+ else if (Matches("CREATE", "SCHEMA"))+ COMPLETE_WITH_QUERY(Query_for_list_of_schemas+ " UNION ALL SELECT 'AUTHORIZATION'");+ else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION"))+ COMPLETE_WITH_QUERY(Query_for_list_of_schema_roles);+ else if (Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION"))+ COMPLETE_WITH_QUERY(Query_for_list_of_schema_roles);+ else if (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))
--
2.30.2
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: ilmari@ilmari.org, pgsql-hackers@lists.postgresql.org
Subject: Re: Tab completion for CREATE SCHEMAAUTHORIZATION
In-Reply-To: <874kc1gdxc.fsf@wibble.ilmari.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox