From: Gilles Darold <gilles.darold@dalibo.com>
To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: [patch] psql tab completion for ALTER DEFAULT PRIVILEGES
Date: Sun, 20 Nov 2016 15:46:14 +0100
Message-ID: <1614593c-e356-5b27-6dba-66320a9bc68b@dalibo.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
Hi,
When tab-completing after ALTER DEFAULT PRIVILEGES ... GRANT|REVOKE,
currently psql injects completion from the GRANT|REVOKE order, rather
than the one expected.
A patch is attached. It adds the right completion to GRANT|REVOKE after
ALTER DEFAULT PRIVILEGES and after FOR ROLE|USER + IN SCHEMA.
If there's no objection I will add it to next commit fest.
Best regards,
--
Gilles Darold
Consultant PostgreSQL
http://dalibo.com - http://dalibo.org
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackersAttachments:patch-completion-alter-default-privileges.diff (text/x-diff, 3.6K) downloaddiff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.cindex b556c00..d0c8eda 100644--- a/src/bin/psql/tab-complete.c+++ b/src/bin/psql/tab-complete.c@@ -1574,9 +1574,23 @@ psql_completion(const char *text, int start, int end)
/* ALTER DEFAULT PRIVILEGES FOR */
else if (Matches4("ALTER", "DEFAULT", "PRIVILEGES", "FOR"))
COMPLETE_WITH_LIST2("ROLE", "USER");
- /* ALTER DEFAULT PRIVILEGES { FOR ROLE ... | IN SCHEMA ... } */- else if (Matches6("ALTER", "DEFAULT", "PRIVILEGES", "FOR", "ROLE|USER", MatchAny) ||- Matches6("ALTER", "DEFAULT", "PRIVILEGES", "IN", "SCHEMA", MatchAny))+ else if (Matches4("ALTER", "DEFAULT", "PRIVILEGES", "IN"))+ COMPLETE_WITH_CONST("SCHEMA");+ /* ALTER DEFAULT PRIVILEGES FOR ROLE ... */+ else if (Matches6("ALTER", "DEFAULT", "PRIVILEGES", "FOR", "ROLE|USER",+ MatchAny))+ COMPLETE_WITH_LIST3("GRANT", "REVOKE", "IN SCHEMA");+ /* ALTER DEFAULT PRIVILEGES IN SCHEMA ... */+ else if (Matches6("ALTER", "DEFAULT", "PRIVILEGES", "IN", "SCHEMA",+ MatchAny))+ COMPLETE_WITH_LIST4("GRANT", "REVOKE", "FOR ROLE", "FOR USER");+ else if (Matches7("ALTER", "DEFAULT", "PRIVILEGES", "IN", "SCHEMA",+ MatchAny, "FOR"))+ COMPLETE_WITH_LIST2("ROLE", "USER");+ else if (Matches9("ALTER", "DEFAULT", "PRIVILEGES", "FOR", "ROLE|USER",+ MatchAny, "IN", "SCHEMA", MatchAny) ||+ Matches9("ALTER", "DEFAULT", "PRIVILEGES", "IN", "SCHEMA",+ MatchAny, "FOR", "ROLE|USER", MatchAny))
COMPLETE_WITH_LIST2("GRANT", "REVOKE");
/* ALTER DOMAIN <name> */
else if (Matches3("ALTER", "DOMAIN", MatchAny))
@@ -2541,10 +2555,18 @@ psql_completion(const char *text, int start, int end)
else if (TailMatches2("FOREIGN", "SERVER"))
COMPLETE_WITH_QUERY(Query_for_list_of_servers);
-/* GRANT && REVOKE --- is allowed inside CREATE SCHEMA, so use TailMatches */+/* GRANT && REVOKE --- is allowed inside CREATE SCHEMA and+ ALTER DEFAULT PRIVILEGES, so use TailMatches */
/* Complete GRANT/REVOKE with a list of roles and privileges */
else if (TailMatches1("GRANT|REVOKE"))
- COMPLETE_WITH_QUERY(Query_for_list_of_roles+ /* With ALTER DEFAULT PRIVILEGES, restrict completion+ to authorized keywords */+ if (HeadMatches3("ALTER","DEFAULT","PRIVILEGES"))+ COMPLETE_WITH_LIST10("SELECT", "INSERT", "UPDATE",+ "DELETE", "TRUNCATE", "REFERENCES", "TRIGGER",+ "EXECUTE", "USAGE", "ALL");+ else+ COMPLETE_WITH_QUERY(Query_for_list_of_roles
" UNION SELECT 'SELECT'"
" UNION SELECT 'INSERT'"
" UNION SELECT 'UPDATE'"
@@ -2585,7 +2607,12 @@ psql_completion(const char *text, int start, int end)
* privilege.
*/
else if (TailMatches3("GRANT|REVOKE", MatchAny, "ON"))
- COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tsvmf,+ /* With ALTER DEFAULT PRIVILEGES, restrict completion+ to authorized keywords */+ if (HeadMatches3("ALTER","DEFAULT","PRIVILEGES"))+ COMPLETE_WITH_LIST4("TABLES", "SEQUENCES", "FUNCTIONS", "TYPES");+ else+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tsvmf,
" UNION SELECT 'ALL FUNCTIONS IN SCHEMA'"
" UNION SELECT 'ALL SEQUENCES IN SCHEMA'"
" UNION SELECT 'ALL TABLES IN SCHEMA'"
@@ -2648,7 +2675,8 @@ psql_completion(const char *text, int start, int end)
else if ((HeadMatches1("GRANT") && TailMatches1("TO")) ||
(HeadMatches1("REVOKE") && TailMatches1("FROM")))
COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
-+ else if (HeadMatches3("ALTER","DEFAULT", "PRIVILEGES") && TailMatches1("TO|FROM"))+ COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
/* Complete "GRANT/REVOKE ... ON * *" with TO/FROM */
else if (HeadMatches1("GRANT") && TailMatches3("ON", MatchAny, MatchAny))
COMPLETE_WITH_CONST("TO");
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: gilles.darold@dalibo.com
Subject: Re: [patch] psql tab completion for ALTER DEFAULT PRIVILEGES
In-Reply-To: <1614593c-e356-5b27-6dba-66320a9bc68b@dalibo.com>
* 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