Skip to content

Commit cbd850b

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 d263648 commit cbd850b

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

src/backend/parser/gram.y

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static void processCASbits(int cas_bits, int location, const char *constrType,
306306
oper_argtypes RuleActionList RuleActionMulti
307307
opt_column_list columnList opt_name_list
308308
sort_clause opt_sort_clause sortby_list index_params
309-
name_list from_clause from_list opt_array_bounds
309+
name_list role_list from_clause from_list opt_array_bounds
310310
qualified_name_list any_name any_name_list
311311
any_operator expr_list attrs
312312
target_list insert_column_list set_target_list
@@ -861,7 +861,7 @@ AlterOptRoleElem:
861861
$$ = makeDefElem("validUntil", (Node *)makeString($3));
862862
}
863863
/* Supported but not documented for roles, for use by ALTER GROUP. */
864-
| USER name_list
864+
| USER role_list
865865
{
866866
$$ = makeDefElem("rolemembers", (Node *)$2);
867867
}
@@ -925,19 +925,19 @@ CreateOptRoleElem:
925925
{
926926
$$ = makeDefElem("sysid", (Node *)makeInteger($2));
927927
}
928-
| ADMIN name_list
928+
| ADMIN role_list
929929
{
930930
$$ = makeDefElem("adminmembers", (Node *)$2);
931931
}
932-
| ROLE name_list
932+
| ROLE role_list
933933
{
934934
$$ = makeDefElem("rolemembers", (Node *)$2);
935935
}
936-
| IN_P ROLE name_list
936+
| IN_P ROLE role_list
937937
{
938938
$$ = makeDefElem("addroleto", (Node *)$3);
939939
}
940-
| IN_P GROUP_P name_list
940+
| IN_P GROUP_P role_list
941941
{
942942
$$ = makeDefElem("addroleto", (Node *)$3);
943943
}
@@ -1036,14 +1036,14 @@ AlterUserSetStmt:
10361036
*****************************************************************************/
10371037

10381038
DropRoleStmt:
1039-
DROP ROLE name_list
1039+
DROP ROLE role_list
10401040
{
10411041
DropRoleStmt *n = makeNode(DropRoleStmt);
10421042
n->missing_ok = FALSE;
10431043
n->roles = $3;
10441044
$$ = (Node *)n;
10451045
}
1046-
| DROP ROLE IF_P EXISTS name_list
1046+
| DROP ROLE IF_P EXISTS role_list
10471047
{
10481048
DropRoleStmt *n = makeNode(DropRoleStmt);
10491049
n->missing_ok = TRUE;
@@ -1062,14 +1062,14 @@ DropRoleStmt:
10621062
*****************************************************************************/
10631063

10641064
DropUserStmt:
1065-
DROP USER name_list
1065+
DROP USER role_list
10661066
{
10671067
DropRoleStmt *n = makeNode(DropRoleStmt);
10681068
n->missing_ok = FALSE;
10691069
n->roles = $3;
10701070
$$ = (Node *)n;
10711071
}
1072-
| DROP USER IF_P EXISTS name_list
1072+
| DROP USER IF_P EXISTS role_list
10731073
{
10741074
DropRoleStmt *n = makeNode(DropRoleStmt);
10751075
n->roles = $5;
@@ -1104,7 +1104,7 @@ CreateGroupStmt:
11041104
*****************************************************************************/
11051105

11061106
AlterGroupStmt:
1107-
ALTER GROUP_P RoleId add_drop USER name_list
1107+
ALTER GROUP_P RoleId add_drop USER role_list
11081108
{
11091109
AlterRoleStmt *n = makeNode(AlterRoleStmt);
11101110
n->role = $3;
@@ -1128,14 +1128,14 @@ add_drop: ADD_P { $$ = +1; }
11281128
*****************************************************************************/
11291129

11301130
DropGroupStmt:
1131-
DROP GROUP_P name_list
1131+
DROP GROUP_P role_list
11321132
{
11331133
DropRoleStmt *n = makeNode(DropRoleStmt);
11341134
n->missing_ok = FALSE;
11351135
n->roles = $3;
11361136
$$ = (Node *)n;
11371137
}
1138-
| DROP GROUP_P IF_P EXISTS name_list
1138+
| DROP GROUP_P IF_P EXISTS role_list
11391139
{
11401140
DropRoleStmt *n = makeNode(DropRoleStmt);
11411141
n->missing_ok = TRUE;
@@ -4688,8 +4688,8 @@ DropOpFamilyStmt:
46884688
*
46894689
*****************************************************************************/
46904690
DropOwnedStmt:
4691-
DROP OWNED BY name_list opt_drop_behavior
4692-
{
4691+
DROP OWNED BY role_list opt_drop_behavior
4692+
{
46934693
DropOwnedStmt *n = makeNode(DropOwnedStmt);
46944694
n->roles = $4;
46954695
n->behavior = $5;
@@ -4698,7 +4698,7 @@ DropOwnedStmt:
46984698
;
46994699

47004700
ReassignOwnedStmt:
4701-
REASSIGN OWNED BY name_list TO name
4701+
REASSIGN OWNED BY role_list TO name
47024702
{
47034703
ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
47044704
n->roles = $4;
@@ -5535,7 +5535,7 @@ function_with_argtypes:
55355535
*****************************************************************************/
55365536

55375537
GrantRoleStmt:
5538-
GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
5538+
GRANT privilege_list TO role_list opt_grant_admin_option opt_granted_by
55395539
{
55405540
GrantRoleStmt *n = makeNode(GrantRoleStmt);
55415541
n->is_grant = true;
@@ -5548,7 +5548,7 @@ GrantRoleStmt:
55485548
;
55495549

55505550
RevokeRoleStmt:
5551-
REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
5551+
REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
55525552
{
55535553
GrantRoleStmt *n = makeNode(GrantRoleStmt);
55545554
n->is_grant = false;
@@ -5558,7 +5558,7 @@ RevokeRoleStmt:
55585558
n->behavior = $6;
55595559
$$ = (Node*)n;
55605560
}
5561-
| REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
5561+
| REVOKE ADMIN OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
55625562
{
55635563
GrantRoleStmt *n = makeNode(GrantRoleStmt);
55645564
n->is_grant = false;
@@ -5604,11 +5604,11 @@ DefACLOption:
56045604
{
56055605
$$ = makeDefElem("schemas", (Node *)$3);
56065606
}
5607-
| FOR ROLE name_list
5607+
| FOR ROLE role_list
56085608
{
56095609
$$ = makeDefElem("roles", (Node *)$3);
56105610
}
5611-
| FOR USER name_list
5611+
| FOR USER role_list
56125612
{
56135613
$$ = makeDefElem("roles", (Node *)$3);
56145614
}
@@ -11783,6 +11783,12 @@ Iconst: ICONST { $$ = $1; };
1178311783
Sconst: SCONST { $$ = $1; };
1178411784
RoleId: NonReservedWord { $$ = $1; };
1178511785

11786+
role_list: RoleId
11787+
{ $$ = list_make1(makeString($1)); }
11788+
| role_list ',' RoleId
11789+
{ $$ = lappend($1, makeString($3)); }
11790+
;
11791+
1178611792
SignedIconst: Iconst { $$ = $1; }
1178711793
| '+' Iconst { $$ = + $2; }
1178811794
| '-' Iconst { $$ = - $2; }

0 commit comments

Comments
 (0)