aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2006-02-04 19:06:47 +0000
committerAndrew Dunstan <andrew@dunslane.net>2006-02-04 19:06:47 +0000
commitf8b54fe6ed7a2eae575d365091d136b4a4068316 (patch)
tree4f3eedce55525759add7704eef65ea66c69989d2 /src/backend
parent3fa9c416ed14f1d46567fdcf99c8d639034dbeec (diff)
downloadpostgresql-f8b54fe6ed7a2eae575d365091d136b4a4068316.tar.gz
postgresql-f8b54fe6ed7a2eae575d365091d136b4a4068316.zip
DROP IF EXISTS for ROLE/USER/GROUP
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/commands/user.c21
-rw-r--r--src/backend/nodes/copyfuncs.c3
-rw-r--r--src/backend/nodes/equalfuncs.c3
-rw-r--r--src/backend/parser/gram.y26
4 files changed, 46 insertions, 7 deletions
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index 0ffcc215017..b3aa2ed8295 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.167 2005/12/23 16:46:39 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.168 2006/02/04 19:06:46 adunstan Exp $
*
*-------------------------------------------------------------------------
*/
@@ -840,9 +840,22 @@ DropRole(DropRoleStmt *stmt)
PointerGetDatum(role),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("role \"%s\" does not exist", role)));
+ {
+ if (!stmt->missing_ok)
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("role \"%s\" does not exist", role)));
+ }
+ else
+ {
+ ereport(NOTICE,
+ (errmsg("role \"%s\" does not exist, skipping",
+ role)));
+ }
+
+ continue;
+ }
roleid = HeapTupleGetOid(tuple);
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index 19b987908bb..6578bf37afd 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.325 2006/01/31 21:39:23 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.326 2006/02/04 19:06:46 adunstan Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2518,6 +2518,7 @@ _copyDropRoleStmt(DropRoleStmt *from)
DropRoleStmt *newnode = makeNode(DropRoleStmt);
COPY_NODE_FIELD(roles);
+ COPY_SCALAR_FIELD(missing_ok);
return newnode;
}
diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c
index e7a9ced0ed3..a9fdc95f6bb 100644
--- a/src/backend/nodes/equalfuncs.c
+++ b/src/backend/nodes/equalfuncs.c
@@ -18,7 +18,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.261 2006/01/31 21:39:23 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.262 2006/02/04 19:06:46 adunstan Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1398,6 +1398,7 @@ static bool
_equalDropRoleStmt(DropRoleStmt *a, DropRoleStmt *b)
{
COMPARE_NODE_FIELD(roles);
+ COMPARE_SCALAR_FIELD(missing_ok);
return true;
}
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index bda5c932548..8c21c421587 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.525 2006/01/31 22:40:03 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.526 2006/02/04 19:06:46 adunstan Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -824,9 +824,17 @@ DropRoleStmt:
DROP ROLE name_list
{
DropRoleStmt *n = makeNode(DropRoleStmt);
+ n->missing_ok = FALSE;
n->roles = $3;
$$ = (Node *)n;
}
+ | DROP ROLE IF_P EXISTS name_list
+ {
+ DropRoleStmt *n = makeNode(DropRoleStmt);
+ n->missing_ok = TRUE;
+ n->roles = $5;
+ $$ = (Node *)n;
+ }
;
/*****************************************************************************
@@ -842,9 +850,17 @@ DropUserStmt:
DROP USER name_list
{
DropRoleStmt *n = makeNode(DropRoleStmt);
+ n->missing_ok = FALSE;
n->roles = $3;
$$ = (Node *)n;
}
+ | DROP USER IF_P EXISTS name_list
+ {
+ DropRoleStmt *n = makeNode(DropRoleStmt);
+ n->roles = $5;
+ n->missing_ok = TRUE;
+ $$ = (Node *)n;
+ }
;
@@ -900,9 +916,17 @@ DropGroupStmt:
DROP GROUP_P name_list
{
DropRoleStmt *n = makeNode(DropRoleStmt);
+ n->missing_ok = FALSE;
n->roles = $3;
$$ = (Node *)n;
}
+ | DROP GROUP_P IF_P EXISTS name_list
+ {
+ DropRoleStmt *n = makeNode(DropRoleStmt);
+ n->missing_ok = TRUE;
+ n->roles = $5;
+ $$ = (Node *)n;
+ }
;