Add support for GRANT SET in psql tab completion

3d14e17 has added support for this query but psql was not able to
complete it.  Spotted while working on a different patch in the same
area.

Reviewed-by: Robert Haas
Discussion: https://postgr.es/m/Y3hw7yvG0VwpC1jq@paquier.xyz
This commit is contained in:
Michael Paquier 2022-12-12 16:47:24 +09:00
parent eae7fe4859
commit 9d0cf57492
1 changed files with 10 additions and 5 deletions

View File

@ -3773,7 +3773,7 @@ psql_completion(const char *text, int start, int end)
*/ */
/* Complete GRANT/REVOKE with a list of roles and privileges */ /* Complete GRANT/REVOKE with a list of roles and privileges */
else if (TailMatches("GRANT|REVOKE") || else if (TailMatches("GRANT|REVOKE") ||
TailMatches("REVOKE", "ADMIN|GRANT|INHERIT", "OPTION", "FOR")) TailMatches("REVOKE", "ADMIN|GRANT|INHERIT|SET", "OPTION", "FOR"))
{ {
/* /*
* With ALTER DEFAULT PRIVILEGES, restrict completion to grantable * With ALTER DEFAULT PRIVILEGES, restrict completion to grantable
@ -3792,10 +3792,11 @@ psql_completion(const char *text, int start, int end)
Privilege_options_of_grant_and_revoke, Privilege_options_of_grant_and_revoke,
"GRANT OPTION FOR", "GRANT OPTION FOR",
"ADMIN OPTION FOR", "ADMIN OPTION FOR",
"INHERIT OPTION FOR"); "INHERIT OPTION FOR",
"SET OPTION FOR");
else if (TailMatches("REVOKE", "GRANT", "OPTION", "FOR")) else if (TailMatches("REVOKE", "GRANT", "OPTION", "FOR"))
COMPLETE_WITH(Privilege_options_of_grant_and_revoke); COMPLETE_WITH(Privilege_options_of_grant_and_revoke);
else if (TailMatches("REVOKE", "ADMIN|INHERIT", "OPTION", "FOR")) else if (TailMatches("REVOKE", "ADMIN|INHERIT|SET", "OPTION", "FOR"))
COMPLETE_WITH_QUERY(Query_for_list_of_roles); COMPLETE_WITH_QUERY(Query_for_list_of_roles);
} }
@ -3803,7 +3804,9 @@ psql_completion(const char *text, int start, int end)
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", "ALTER")) TailMatches("REVOKE", "GRANT", "OPTION", "FOR", "ALTER"))
COMPLETE_WITH("SYSTEM"); COMPLETE_WITH("SYSTEM");
else if (TailMatches("GRANT|REVOKE", "SET") || else if (TailMatches("REVOKE", "SET"))
COMPLETE_WITH("ON PARAMETER", "OPTION FOR");
else if (TailMatches("GRANT", "SET") ||
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", "SET") || TailMatches("REVOKE", "GRANT", "OPTION", "FOR", "SET") ||
TailMatches("GRANT|REVOKE", "ALTER", "SYSTEM") || TailMatches("GRANT|REVOKE", "ALTER", "SYSTEM") ||
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", "ALTER", "SYSTEM")) TailMatches("REVOKE", "GRANT", "OPTION", "FOR", "ALTER", "SYSTEM"))
@ -3942,14 +3945,16 @@ psql_completion(const char *text, int start, int end)
else if (HeadMatches("GRANT") && TailMatches("TO", MatchAny)) else if (HeadMatches("GRANT") && TailMatches("TO", MatchAny))
COMPLETE_WITH("WITH ADMIN", COMPLETE_WITH("WITH ADMIN",
"WITH INHERIT", "WITH INHERIT",
"WITH SET",
"WITH GRANT OPTION", "WITH GRANT OPTION",
"GRANTED BY"); "GRANTED BY");
else if (HeadMatches("GRANT") && TailMatches("TO", MatchAny, "WITH")) else if (HeadMatches("GRANT") && TailMatches("TO", MatchAny, "WITH"))
COMPLETE_WITH("ADMIN", COMPLETE_WITH("ADMIN",
"INHERIT", "INHERIT",
"SET",
"GRANT OPTION"); "GRANT OPTION");
else if (HeadMatches("GRANT") && else if (HeadMatches("GRANT") &&
(TailMatches("TO", MatchAny, "WITH", "ADMIN|INHERIT"))) (TailMatches("TO", MatchAny, "WITH", "ADMIN|INHERIT|SET")))
COMPLETE_WITH("OPTION", "TRUE", "FALSE"); COMPLETE_WITH("OPTION", "TRUE", "FALSE");
else if (HeadMatches("GRANT") && TailMatches("TO", MatchAny, "WITH", MatchAny, "OPTION")) else if (HeadMatches("GRANT") && TailMatches("TO", MatchAny, "WITH", MatchAny, "OPTION"))
COMPLETE_WITH("GRANTED BY"); COMPLETE_WITH("GRANTED BY");