All,
> I agree that we should probably seperate the concerns here. Personally,
> I like the idea of being able to say "CURRENT_USER" in utility commands
> to refer to the current user where a role would normally be expected, as
> I could see it simplifying things for some applications, but that's a
> new feature and independent of making role-vs-user cases more
> consistent.
>
So, I've been doing a little digging and it would appear that the ALTER
ROLE/USER consistency was brought up earlier in the year.
http://www.postgresql.org/message-id/cadyruxmv-tvsbv7mttcs+qedny6xj1+krtzfowvuhdjc5mg...@mail.gmail.com
It was returned with feedback in Commitfest 2014-06 and apparently lost
steam:
https://commitfest.postgresql.org/action/patch_view?id=1408
Tom put forward a suggestion for how to fix it:
http://www.postgresql.org/message-id/[email protected]
I have taken that patch and updated the documentation (attached) and ran it
through some cursory testing.
At any rate, this is probably a good starting point for those changes.
-Adam
--
Adam Brightwell - [email protected]
Database Engineer - www.crunchydatasolutions.com
diff --git a/doc/src/sgml/ref/alter_user.sgml b/doc/src/sgml/ref/alter_user.sgml
new file mode 100644
index 58ae1da..ac05682
*** a/doc/src/sgml/ref/alter_user.sgml
--- b/doc/src/sgml/ref/alter_user.sgml
*************** ALTER USER <replaceable class="PARAMETER
*** 38,47 ****
ALTER USER <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
! ALTER USER <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
! ALTER USER <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
! ALTER USER <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>configuration_parameter</replaceable>
! ALTER USER <replaceable class="PARAMETER">name</replaceable> RESET ALL
</synopsis>
</refsynopsisdiv>
--- 38,47 ----
ALTER USER <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
! ALTER USER <replaceable class="PARAMETER">name</replaceable> [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
! ALTER USER { <replaceable class="PARAMETER">name</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
! ALTER USER { <replaceable class="PARAMETER">name</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] RESET <replaceable>configuration_parameter</replaceable>
! ALTER USER { <replaceable class="PARAMETER">name</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] RESET ALL
</synopsis>
</refsynopsisdiv>
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
new file mode 100644
index 0de9584..d7c0586
*** a/src/backend/parser/gram.y
--- b/src/backend/parser/gram.y
*************** static Node *makeRecursiveViewSelect(cha
*** 230,236 ****
AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt AlterForeignTableStmt
! AlterCompositeTypeStmt AlterUserStmt AlterUserMappingStmt AlterUserSetStmt
AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt
AlterDefaultPrivilegesStmt DefACLAction
AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
--- 230,236 ----
AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt AlterForeignTableStmt
! AlterCompositeTypeStmt AlterUserMappingStmt
AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt
AlterDefaultPrivilegesStmt DefACLAction
AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
*************** static Node *makeRecursiveViewSelect(cha
*** 520,525 ****
--- 520,527 ----
%type <str> opt_existing_window_name
%type <boolean> opt_if_not_exists
+ %type <str> role_or_user
+
/*
* Non-keyword token types. These are hard-wired into the "flex" lexer.
* They must be listed first so that their numeric codes do not depend on
*************** stmt :
*** 756,763 ****
| AlterTSConfigurationStmt
| AlterTSDictionaryStmt
| AlterUserMappingStmt
- | AlterUserSetStmt
- | AlterUserStmt
| AnalyzeStmt
| CheckPointStmt
| ClosePortalStmt
--- 758,763 ----
*************** CreateUserStmt:
*** 1033,1042 ****
*
* Alter a postgresql DBMS role
*
*****************************************************************************/
AlterRoleStmt:
! ALTER ROLE RoleId opt_with AlterOptRoleList
{
AlterRoleStmt *n = makeNode(AlterRoleStmt);
n->role = $3;
--- 1033,1044 ----
*
* Alter a postgresql DBMS role
*
+ * ALTER USER is accepted interchangeably with ALTER ROLE.
+ *
*****************************************************************************/
AlterRoleStmt:
! ALTER role_or_user RoleId opt_with AlterOptRoleList
{
AlterRoleStmt *n = makeNode(AlterRoleStmt);
n->role = $3;
*************** AlterRoleStmt:
*** 1046,1058 ****
}
;
opt_in_database:
/* EMPTY */ { $$ = NULL; }
| IN_P DATABASE database_name { $$ = $3; }
;
AlterRoleSetStmt:
! ALTER ROLE RoleId opt_in_database SetResetClause
{
AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
n->role = $3;
--- 1048,1065 ----
}
;
+ role_or_user:
+ ROLE {}
+ | USER {}
+ ;
+
opt_in_database:
/* EMPTY */ { $$ = NULL; }
| IN_P DATABASE database_name { $$ = $3; }
;
AlterRoleSetStmt:
! ALTER role_or_user RoleId opt_in_database SetResetClause
{
AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
n->role = $3;
*************** AlterRoleSetStmt:
*** 1060,1066 ****
n->setstmt = $5;
$$ = (Node *)n;
}
! | ALTER ROLE ALL opt_in_database SetResetClause
{
AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
n->role = NULL;
--- 1067,1073 ----
n->setstmt = $5;
$$ = (Node *)n;
}
! | ALTER role_or_user ALL opt_in_database SetResetClause
{
AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
n->role = NULL;
*************** AlterRoleSetStmt:
*** 1073,1108 ****
/*****************************************************************************
*
- * Alter a postgresql DBMS user
- *
- *****************************************************************************/
-
- AlterUserStmt:
- ALTER USER RoleId opt_with AlterOptRoleList
- {
- AlterRoleStmt *n = makeNode(AlterRoleStmt);
- n->role = $3;
- n->action = +1; /* add, if there are members */
- n->options = $5;
- $$ = (Node *)n;
- }
- ;
-
-
- AlterUserSetStmt:
- ALTER USER RoleId SetResetClause
- {
- AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
- n->role = $3;
- n->database = NULL;
- n->setstmt = $4;
- $$ = (Node *)n;
- }
- ;
-
-
- /*****************************************************************************
- *
* Drop a postgresql DBMS role
*
* XXX Ideally this would have CASCADE/RESTRICT options, but since a role
--- 1080,1085 ----
*************** DropUserMappingStmt: DROP USER MAPPING F
*** 4493,4501 ****
* QUERY :
* ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
*
****************************************************************************/
! AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
{
AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
n->username = $5;
--- 4470,4483 ----
* QUERY :
* ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
*
+ * Note: we also accept "ALTER ROLE MAPPING", because distinguishing that
+ * case in the grammar would require us to distinguish ROLE from USER in all
+ * other ALTER cases, and we don't want to do that. However, that spelling
+ * of the command is nonstandard and is not documented.
+ *
****************************************************************************/
! AlterUserMappingStmt: ALTER role_or_user MAPPING FOR auth_ident SERVER name alter_generic_options
{
AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
n->username = $5;
*************** RenameStmt: ALTER AGGREGATE func_name ag
*** 7611,7626 ****
n->newname = $7;
$$ = (Node *)n;
}
! | ALTER ROLE RoleId RENAME TO RoleId
! {
! RenameStmt *n = makeNode(RenameStmt);
! n->renameType = OBJECT_ROLE;
! n->subname = $3;
! n->newname = $6;
! n->missing_ok = false;
! $$ = (Node *)n;
! }
! | ALTER USER RoleId RENAME TO RoleId
{
RenameStmt *n = makeNode(RenameStmt);
n->renameType = OBJECT_ROLE;
--- 7593,7599 ----
n->newname = $7;
$$ = (Node *)n;
}
! | ALTER role_or_user RoleId RENAME TO RoleId
{
RenameStmt *n = makeNode(RenameStmt);
n->renameType = OBJECT_ROLE;
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers