Further unify ROLE and USER command grammar rules
authorPeter Eisentraut <[email protected]>
Tue, 1 Aug 2017 00:36:32 +0000 (20:36 -0400)
committerPeter Eisentraut <[email protected]>
Fri, 4 Aug 2017 00:34:45 +0000 (20:34 -0400)
ALTER USER ... SET did not support all the syntax variants of ALTER ROLE
...  SET.  Fix that, and to avoid further deviations of this kind, unify
many the grammar rules for ROLE/USER/GROUP commands.

Reported-by: Pavel Golub <[email protected]>
doc/src/sgml/ref/alter_user.sgml
src/backend/parser/gram.y
src/test/regress/expected/rolenames.out

index 9b8a39b37681209700f207e123806ea0833d9edb..411a6dcc389271891a4d0dc2786bd741a0f2d231 100644 (file)
@@ -38,10 +38,10 @@ ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> [ WIT
 
 ALTER USER <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
 
-ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
-ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
-ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> RESET <replaceable>configuration_parameter</replaceable>
-ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> RESET ALL
+ALTER USER { <replaceable class="PARAMETER">role_specification</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
+ALTER USER { <replaceable class="PARAMETER">role_specification</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
+ALTER USER { <replaceable class="PARAMETER">role_specification</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] RESET <replaceable>configuration_parameter</replaceable>
+ALTER USER { <replaceable class="PARAMETER">role_specification</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] RESET ALL
 
 <phrase>where <replaceable class="PARAMETER">role_specification</replaceable> can be:</phrase>
 
index 62092ff7ec357c6d29d2a3cb728ee2496a3eac5b..7d0de99baf2ceda667d3c201f1001096181e367f 100644 (file)
@@ -250,7 +250,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
                AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
                AlterOperatorStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
                AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt AlterForeignTableStmt
-               AlterCompositeTypeStmt AlterUserStmt AlterUserMappingStmt AlterUserSetStmt
+               AlterCompositeTypeStmt AlterUserMappingStmt
                AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt
                AlterDefaultPrivilegesStmt DefACLAction
                AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
@@ -262,9 +262,9 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
                CreateAssertStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
                CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
                CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
-               DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
+               DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
                DropAssertStmt DropCastStmt DropRoleStmt
-               DropUserStmt DropdbStmt DropTableSpaceStmt
+               DropdbStmt DropTableSpaceStmt
                DropTransformStmt
                DropUserMappingStmt ExplainStmt FetchStmt
                GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
@@ -841,8 +841,6 @@ stmt :
                        | AlterTSConfigurationStmt
                        | AlterTSDictionaryStmt
                        | AlterUserMappingStmt
-                       | AlterUserSetStmt
-                       | AlterUserStmt
                        | AnalyzeStmt
                        | CheckPointStmt
                        | ClosePortalStmt
@@ -890,7 +888,6 @@ stmt :
                        | DoStmt
                        | DropAssertStmt
                        | DropCastStmt
-                       | DropGroupStmt
                        | DropOpClassStmt
                        | DropOpFamilyStmt
                        | DropOwnedStmt
@@ -900,7 +897,6 @@ stmt :
                        | DropTableSpaceStmt
                        | DropTransformStmt
                        | DropRoleStmt
-                       | DropUserStmt
                        | DropUserMappingStmt
                        | DropdbStmt
                        | ExecuteStmt
@@ -1130,6 +1126,14 @@ AlterRoleStmt:
                                        n->options = $5;
                                        $$ = (Node *)n;
                                 }
+                       | ALTER USER RoleSpec opt_with AlterOptRoleList
+                                {
+                                       AlterRoleStmt *n = makeNode(AlterRoleStmt);
+                                       n->role = $3;
+                                       n->action = +1; /* add, if there are members */
+                                       n->options = $5;
+                                       $$ = (Node *)n;
+                                }
                ;
 
 opt_in_database:
@@ -1154,37 +1158,23 @@ AlterRoleSetStmt:
                                        n->setstmt = $5;
                                        $$ = (Node *)n;
                                }
-               ;
-
-
-/*****************************************************************************
- *
- * Alter a postgresql DBMS user
- *
- *****************************************************************************/
-
-AlterUserStmt:
-                       ALTER USER RoleSpec opt_with AlterOptRoleList
-                                {
-                                       AlterRoleStmt *n = makeNode(AlterRoleStmt);
+                       | ALTER USER RoleSpec opt_in_database SetResetClause
+                               {
+                                       AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
                                        n->role = $3;
-                                       n->action = +1; /* add, if there are members */
-                                       n->options = $5;
+                                       n->database = $4;
+                                       n->setstmt = $5;
                                        $$ = (Node *)n;
-                                }
-               ;
-
-
-AlterUserSetStmt:
-                       ALTER USER RoleSpec SetResetClause
+                               }
+                       | ALTER USER ALL opt_in_database SetResetClause
                                {
                                        AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
-                                       n->role = $3;
-                                       n->database = NULL;
-                                       n->setstmt = $4;
+                                       n->role = NULL;
+                                       n->database = $4;
+                                       n->setstmt = $5;
                                        $$ = (Node *)n;
                                }
-                       ;
+               ;
 
 
 /*****************************************************************************
@@ -1211,17 +1201,7 @@ DropRoleStmt:
                                        n->roles = $5;
                                        $$ = (Node *)n;
                                }
-                       ;
-
-/*****************************************************************************
- *
- * Drop a postgresql DBMS user
- *
- * XXX As with DROP ROLE, no CASCADE/RESTRICT here.
- *****************************************************************************/
-
-DropUserStmt:
-                       DROP USER role_list
+                       | DROP USER role_list
                                {
                                        DropRoleStmt *n = makeNode(DropRoleStmt);
                                        n->missing_ok = FALSE;
@@ -1235,6 +1215,20 @@ DropUserStmt:
                                        n->missing_ok = TRUE;
                                        $$ = (Node *)n;
                                }
+                       | DROP GROUP_P role_list
+                               {
+                                       DropRoleStmt *n = makeNode(DropRoleStmt);
+                                       n->missing_ok = FALSE;
+                                       n->roles = $3;
+                                       $$ = (Node *)n;
+                               }
+                       | DROP GROUP_P IF_P EXISTS role_list
+                               {
+                                       DropRoleStmt *n = makeNode(DropRoleStmt);
+                                       n->missing_ok = TRUE;
+                                       n->roles = $5;
+                                       $$ = (Node *)n;
+                               }
                        ;
 
 
@@ -1279,31 +1273,6 @@ add_drop:        ADD_P                                                                   { $$ = +1; }
                ;
 
 
-/*****************************************************************************
- *
- * Drop a postgresql group
- *
- * XXX As with DROP ROLE, no CASCADE/RESTRICT here.
- *****************************************************************************/
-
-DropGroupStmt:
-                       DROP GROUP_P role_list
-                               {
-                                       DropRoleStmt *n = makeNode(DropRoleStmt);
-                                       n->missing_ok = FALSE;
-                                       n->roles = $3;
-                                       $$ = (Node *)n;
-                               }
-                       | DROP GROUP_P IF_P EXISTS role_list
-                               {
-                                       DropRoleStmt *n = makeNode(DropRoleStmt);
-                                       n->missing_ok = TRUE;
-                                       n->roles = $5;
-                                       $$ = (Node *)n;
-                               }
-               ;
-
-
 /*****************************************************************************
  *
  * Manipulate a schema
index fd058e4f7d2d94eb7f7dd264789d3e3f0797c006..dce82f5de7ef9ec7f9b5e4cb2a41ed42476b12c8 100644 (file)
@@ -310,9 +310,9 @@ ERROR:  syntax error at or near "CURRENT_ROLE"
 LINE 1: ALTER USER CURRENT_ROLE WITH LOGIN;
                    ^
 ALTER USER ALL WITH REPLICATION; -- error
-ERROR:  syntax error at or near "ALL"
+ERROR:  syntax error at or near "WITH"
 LINE 1: ALTER USER ALL WITH REPLICATION;
-                   ^
+                       ^
 ALTER USER SESSION_ROLE WITH NOREPLICATION; -- error
 ERROR:  role "session_role" does not exist
 ALTER USER PUBLIC WITH NOREPLICATION; -- error
@@ -392,9 +392,6 @@ ALTER USER SESSION_USER SET application_name to 'BAR';
 ALTER USER "current_user" SET application_name to 'FOOFOO';
 ALTER USER "Public" SET application_name to 'BARBAR';
 ALTER USER ALL SET application_name to 'SLAP';
-ERROR:  syntax error at or near "ALL"
-LINE 1: ALTER USER ALL SET application_name to 'SLAP';
-                   ^
 SELECT * FROM chksetconfig();
  db  |       role       |  rolkeyword  |         setconfig         
 -----+------------------+--------------+---------------------------
@@ -419,9 +416,6 @@ ALTER USER SESSION_USER RESET application_name;
 ALTER USER "current_user" RESET application_name;
 ALTER USER "Public" RESET application_name;
 ALTER USER ALL RESET application_name;
-ERROR:  syntax error at or near "ALL"
-LINE 1: ALTER USER ALL RESET application_name;
-                   ^
 SELECT * FROM chksetconfig();
  db | role | rolkeyword | setconfig 
 ----+------+------------+-----------