Skip to content

Commit d1e3070

Browse files
committed
Allow type_func_name_keywords in even more places
A while back, 2c92eda allowed type_func_name_keywords to be used in more places, including role identifiers. Unfortunately, that commit missed out on cases where name_list was used for lists-of-roles, eg: for DROP ROLE. This resulted in the unfortunate situation that you could CREATE a role with a type_func_name_keywords-allowed identifier, but not DROP it (directly- ALTER could be used to rename it to something which could be DROP'd). This extends allowing type_func_name_keywords to places where role lists can be used. Back-patch to 9.0, as 2c92eda was.
1 parent 0950d67 commit d1e3070

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

src/backend/parser/gram.y

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
329329
oper_argtypes RuleActionList RuleActionMulti
330330
opt_column_list columnList opt_name_list
331331
sort_clause opt_sort_clause sortby_list index_params
332-
name_list from_clause from_list opt_array_bounds
332+
name_list role_list from_clause from_list opt_array_bounds
333333
qualified_name_list any_name any_name_list
334334
any_operator expr_list attrs
335335
target_list insert_column_list set_target_list
@@ -889,7 +889,7 @@ AlterOptRoleElem:
889889
$$ = makeDefElem("validUntil", (Node *)makeString($3));
890890
}
891891
/* Supported but not documented for roles, for use by ALTER GROUP. */
892-
| USER name_list
892+
| USER role_list
893893
{
894894
$$ = makeDefElem("rolemembers", (Node *)$2);
895895
}
@@ -953,19 +953,19 @@ CreateOptRoleElem:
953953
{
954954
$$ = makeDefElem("sysid", (Node *)makeInteger($2));
955955
}
956-
| ADMIN name_list
956+
| ADMIN role_list
957957
{
958958
$$ = makeDefElem("adminmembers", (Node *)$2);
959959
}
960-
| ROLE name_list
960+
| ROLE role_list
961961
{
962962
$$ = makeDefElem("rolemembers", (Node *)$2);
963963
}
964-
| IN_P ROLE name_list
964+
| IN_P ROLE role_list
965965
{
966966
$$ = makeDefElem("addroleto", (Node *)$3);
967967
}
968-
| IN_P GROUP_P name_list
968+
| IN_P GROUP_P role_list
969969
{
970970
$$ = makeDefElem("addroleto", (Node *)$3);
971971
}
@@ -1072,14 +1072,14 @@ AlterUserSetStmt:
10721072
*****************************************************************************/
10731073

10741074
DropRoleStmt:
1075-
DROP ROLE name_list
1075+
DROP ROLE role_list
10761076
{
10771077
DropRoleStmt *n = makeNode(DropRoleStmt);
10781078
n->missing_ok = FALSE;
10791079
n->roles = $3;
10801080
$$ = (Node *)n;
10811081
}
1082-
| DROP ROLE IF_P EXISTS name_list
1082+
| DROP ROLE IF_P EXISTS role_list
10831083
{
10841084
DropRoleStmt *n = makeNode(DropRoleStmt);
10851085
n->missing_ok = TRUE;
@@ -1098,14 +1098,14 @@ DropRoleStmt:
10981098
*****************************************************************************/
10991099

11001100
DropUserStmt:
1101-
DROP USER name_list
1101+
DROP USER role_list
11021102
{
11031103
DropRoleStmt *n = makeNode(DropRoleStmt);
11041104
n->missing_ok = FALSE;
11051105
n->roles = $3;
11061106
$$ = (Node *)n;
11071107
}
1108-
| DROP USER IF_P EXISTS name_list
1108+
| DROP USER IF_P EXISTS role_list
11091109
{
11101110
DropRoleStmt *n = makeNode(DropRoleStmt);
11111111
n->roles = $5;
@@ -1140,7 +1140,7 @@ CreateGroupStmt:
11401140
*****************************************************************************/
11411141

11421142
AlterGroupStmt:
1143-
ALTER GROUP_P RoleId add_drop USER name_list
1143+
ALTER GROUP_P RoleId add_drop USER role_list
11441144
{
11451145
AlterRoleStmt *n = makeNode(AlterRoleStmt);
11461146
n->role = $3;
@@ -1164,14 +1164,14 @@ add_drop: ADD_P { $$ = +1; }
11641164
*****************************************************************************/
11651165

11661166
DropGroupStmt:
1167-
DROP GROUP_P name_list
1167+
DROP GROUP_P role_list
11681168
{
11691169
DropRoleStmt *n = makeNode(DropRoleStmt);
11701170
n->missing_ok = FALSE;
11711171
n->roles = $3;
11721172
$$ = (Node *)n;
11731173
}
1174-
| DROP GROUP_P IF_P EXISTS name_list
1174+
| DROP GROUP_P IF_P EXISTS role_list
11751175
{
11761176
DropRoleStmt *n = makeNode(DropRoleStmt);
11771177
n->missing_ok = TRUE;
@@ -5047,7 +5047,7 @@ DropOpFamilyStmt:
50475047
*
50485048
*****************************************************************************/
50495049
DropOwnedStmt:
5050-
DROP OWNED BY name_list opt_drop_behavior
5050+
DROP OWNED BY role_list opt_drop_behavior
50515051
{
50525052
DropOwnedStmt *n = makeNode(DropOwnedStmt);
50535053
n->roles = $4;
@@ -5057,7 +5057,7 @@ DropOwnedStmt:
50575057
;
50585058

50595059
ReassignOwnedStmt:
5060-
REASSIGN OWNED BY name_list TO name
5060+
REASSIGN OWNED BY role_list TO name
50615061
{
50625062
ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
50635063
n->roles = $4;
@@ -5923,7 +5923,7 @@ function_with_argtypes:
59235923
*****************************************************************************/
59245924

59255925
GrantRoleStmt:
5926-
GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
5926+
GRANT privilege_list TO role_list opt_grant_admin_option opt_granted_by
59275927
{
59285928
GrantRoleStmt *n = makeNode(GrantRoleStmt);
59295929
n->is_grant = true;
@@ -5936,7 +5936,7 @@ GrantRoleStmt:
59365936
;
59375937

59385938
RevokeRoleStmt:
5939-
REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
5939+
REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
59405940
{
59415941
GrantRoleStmt *n = makeNode(GrantRoleStmt);
59425942
n->is_grant = false;
@@ -5946,7 +5946,7 @@ RevokeRoleStmt:
59465946
n->behavior = $6;
59475947
$$ = (Node*)n;
59485948
}
5949-
| REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
5949+
| REVOKE ADMIN OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
59505950
{
59515951
GrantRoleStmt *n = makeNode(GrantRoleStmt);
59525952
n->is_grant = false;
@@ -5992,11 +5992,11 @@ DefACLOption:
59925992
{
59935993
$$ = makeDefElem("schemas", (Node *)$3);
59945994
}
5995-
| FOR ROLE name_list
5995+
| FOR ROLE role_list
59965996
{
59975997
$$ = makeDefElem("roles", (Node *)$3);
59985998
}
5999-
| FOR USER name_list
5999+
| FOR USER role_list
60006000
{
60016001
$$ = makeDefElem("roles", (Node *)$3);
60026002
}
@@ -12587,6 +12587,12 @@ Iconst: ICONST { $$ = $1; };
1258712587
Sconst: SCONST { $$ = $1; };
1258812588
RoleId: NonReservedWord { $$ = $1; };
1258912589

12590+
role_list: RoleId
12591+
{ $$ = list_make1(makeString($1)); }
12592+
| role_list ',' RoleId
12593+
{ $$ = lappend($1, makeString($3)); }
12594+
;
12595+
1259012596
SignedIconst: Iconst { $$ = $1; }
1259112597
| '+' Iconst { $$ = + $2; }
1259212598
| '-' Iconst { $$ = - $2; }

0 commit comments

Comments
 (0)