Commit 131f801d authored by Tom Lane's avatar Tom Lane

First phase of applying Rod Taylor's pg_depend patch. This just adds

RESTRICT/CASCADE syntax to the DROP commands that need it, and propagates
the behavioral option through the parser to the routines that execute
drops.  Doesn't do anything useful yet, but I figured I'd commit these
changes so I could get out of the parser area while working on the rest.
parent a3ec44a5
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.75 2002/06/20 20:29:27 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.76 2002/07/01 15:27:45 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -560,14 +560,9 @@ GetDefaultOpClass(Oid attrType, Oid accessMethodId) ...@@ -560,14 +560,9 @@ GetDefaultOpClass(Oid attrType, Oid accessMethodId)
/* /*
* RemoveIndex * RemoveIndex
* Deletes an index. * Deletes an index.
*
* Exceptions:
* BadArg if name is invalid.
* "ERROR" if index nonexistent.
* ...
*/ */
void void
RemoveIndex(RangeVar *relation) RemoveIndex(RangeVar *relation, DropBehavior behavior)
{ {
Oid indOid; Oid indOid;
HeapTuple tuple; HeapTuple tuple;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/operatorcmds.c,v 1.3 2002/04/27 03:45:01 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/operatorcmds.c,v 1.4 2002/07/01 15:27:46 tgl Exp $
* *
* DESCRIPTION * DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the * The "DefineFoo" routines take the parse tree and pick out the
...@@ -209,18 +209,13 @@ DefineOperator(List *names, List *parameters) ...@@ -209,18 +209,13 @@ DefineOperator(List *names, List *parameters)
/* /*
* RemoveOperator * RemoveOperator
* Deletes an operator. * Deletes an operator.
*
* Exceptions:
* BadArg if name is invalid.
* BadArg if type1 is invalid.
* "ERROR" if operator nonexistent.
* ...
*/ */
void void
RemoveOperator(List *operatorName, /* operator name */ RemoveOperator(RemoveOperStmt *stmt)
TypeName *typeName1, /* left argument type name */
TypeName *typeName2) /* right argument type name */
{ {
List *operatorName = stmt->opname;
TypeName *typeName1 = (TypeName *) lfirst(stmt->args);
TypeName *typeName2 = (TypeName *) lsecond(stmt->args);
Oid operOid; Oid operOid;
Relation relation; Relation relation;
HeapTuple tup; HeapTuple tup;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.17 2002/06/17 14:31:32 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.18 2002/07/01 15:27:46 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
#include "optimizer/planmain.h" #include "optimizer/planmain.h"
#include "optimizer/prep.h" #include "optimizer/prep.h"
#include "parser/parse.h"
#include "parser/parse_coerce.h" #include "parser/parse_coerce.h"
#include "parser/parse_expr.h" #include "parser/parse_expr.h"
#include "parser/parse_relation.h" #include "parser/parse_relation.h"
...@@ -280,7 +279,7 @@ DefineRelation(CreateStmt *stmt, char relkind) ...@@ -280,7 +279,7 @@ DefineRelation(CreateStmt *stmt, char relkind)
* themselves will be destroyed, too. * themselves will be destroyed, too.
*/ */
void void
RemoveRelation(const RangeVar *relation) RemoveRelation(const RangeVar *relation, DropBehavior behavior)
{ {
Oid relOid; Oid relOid;
...@@ -2336,7 +2335,7 @@ AlterTableAlterColumnFlags(Oid myrelid, ...@@ -2336,7 +2335,7 @@ AlterTableAlterColumnFlags(Oid myrelid,
void void
AlterTableDropColumn(Oid myrelid, AlterTableDropColumn(Oid myrelid,
bool inh, const char *colName, bool inh, const char *colName,
int behavior) DropBehavior behavior)
{ {
elog(ERROR, "ALTER TABLE / DROP COLUMN is not implemented"); elog(ERROR, "ALTER TABLE / DROP COLUMN is not implemented");
} }
...@@ -2669,7 +2668,7 @@ AlterTableAddConstraint(Oid myrelid, ...@@ -2669,7 +2668,7 @@ AlterTableAddConstraint(Oid myrelid,
void void
AlterTableDropConstraint(Oid myrelid, AlterTableDropConstraint(Oid myrelid,
bool inh, const char *constrName, bool inh, const char *constrName,
int behavior) DropBehavior behavior)
{ {
Relation rel; Relation rel;
int deleted; int deleted;
...@@ -2678,7 +2677,7 @@ AlterTableDropConstraint(Oid myrelid, ...@@ -2678,7 +2677,7 @@ AlterTableDropConstraint(Oid myrelid,
* We don't support CASCADE yet - in fact, RESTRICT doesn't work to * We don't support CASCADE yet - in fact, RESTRICT doesn't work to
* the spec either! * the spec either!
*/ */
if (behavior == CASCADE) if (behavior == DROP_CASCADE)
elog(ERROR, "ALTER TABLE / DROP CONSTRAINT does not support the CASCADE keyword"); elog(ERROR, "ALTER TABLE / DROP CONSTRAINT does not support the CASCADE keyword");
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.3 2002/05/03 00:32:16 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.4 2002/07/01 15:27:48 tgl Exp $
* *
* DESCRIPTION * DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the * The "DefineFoo" routines take the parse tree and pick out the
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#include "commands/comment.h" #include "commands/comment.h"
#include "commands/defrem.h" #include "commands/defrem.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "parser/parse.h"
#include "parser/parse_func.h" #include "parser/parse_func.h"
#include "parser/parse_type.h" #include "parser/parse_type.h"
#include "utils/acl.h" #include "utils/acl.h"
...@@ -268,7 +267,7 @@ DefineType(List *names, List *parameters) ...@@ -268,7 +267,7 @@ DefineType(List *names, List *parameters)
* only work on scalar types. * only work on scalar types.
*/ */
void void
RemoveType(List *names) RemoveType(List *names, DropBehavior behavior)
{ {
TypeName *typename; TypeName *typename;
Relation relation; Relation relation;
...@@ -574,7 +573,7 @@ DefineDomain(CreateDomainStmt *stmt) ...@@ -574,7 +573,7 @@ DefineDomain(CreateDomainStmt *stmt)
* Removes a domain. * Removes a domain.
*/ */
void void
RemoveDomain(List *names, int behavior) RemoveDomain(List *names, DropBehavior behavior)
{ {
TypeName *typename; TypeName *typename;
Relation relation; Relation relation;
...@@ -583,7 +582,7 @@ RemoveDomain(List *names, int behavior) ...@@ -583,7 +582,7 @@ RemoveDomain(List *names, int behavior)
char typtype; char typtype;
/* CASCADE unsupported */ /* CASCADE unsupported */
if (behavior == CASCADE) if (behavior == DROP_CASCADE)
elog(ERROR, "DROP DOMAIN does not support the CASCADE keyword"); elog(ERROR, "DROP DOMAIN does not support the CASCADE keyword");
/* Make a TypeName so we can use standard type lookup machinery */ /* Make a TypeName so we can use standard type lookup machinery */
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: view.c,v 1.64 2002/06/20 20:29:27 momjian Exp $ * $Id: view.c,v 1.65 2002/07/01 15:27:49 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -248,14 +248,13 @@ DefineView(const RangeVar *view, Query *viewParse) ...@@ -248,14 +248,13 @@ DefineView(const RangeVar *view, Query *viewParse)
DefineViewRules(view, viewParse); DefineViewRules(view, viewParse);
} }
/*------------------------------------------------------------------ /*
* RemoveView * RemoveView
* *
* Remove a view given its name * Remove a view given its name
*------------------------------------------------------------------
*/ */
void void
RemoveView(const RangeVar *view) RemoveView(const RangeVar *view, DropBehavior behavior)
{ {
Oid viewOid; Oid viewOid;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.191 2002/06/20 20:29:29 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.192 2002/07/01 15:27:51 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2115,6 +2115,7 @@ _copyRemoveAggrStmt(RemoveAggrStmt *from) ...@@ -2115,6 +2115,7 @@ _copyRemoveAggrStmt(RemoveAggrStmt *from)
Node_Copy(from, newnode, aggname); Node_Copy(from, newnode, aggname);
Node_Copy(from, newnode, aggtype); Node_Copy(from, newnode, aggtype);
newnode->behavior = from->behavior;
return newnode; return newnode;
} }
...@@ -2126,6 +2127,7 @@ _copyRemoveFuncStmt(RemoveFuncStmt *from) ...@@ -2126,6 +2127,7 @@ _copyRemoveFuncStmt(RemoveFuncStmt *from)
Node_Copy(from, newnode, funcname); Node_Copy(from, newnode, funcname);
Node_Copy(from, newnode, args); Node_Copy(from, newnode, args);
newnode->behavior = from->behavior;
return newnode; return newnode;
} }
...@@ -2137,6 +2139,7 @@ _copyRemoveOperStmt(RemoveOperStmt *from) ...@@ -2137,6 +2139,7 @@ _copyRemoveOperStmt(RemoveOperStmt *from)
Node_Copy(from, newnode, opname); Node_Copy(from, newnode, opname);
Node_Copy(from, newnode, args); Node_Copy(from, newnode, args);
newnode->behavior = from->behavior;
return newnode; return newnode;
} }
...@@ -2395,6 +2398,7 @@ _copyDropPropertyStmt(DropPropertyStmt *from) ...@@ -2395,6 +2398,7 @@ _copyDropPropertyStmt(DropPropertyStmt *from)
if (from->property) if (from->property)
newnode->property = pstrdup(from->property); newnode->property = pstrdup(from->property);
newnode->removeType = from->removeType; newnode->removeType = from->removeType;
newnode->behavior = from->behavior;
return newnode; return newnode;
} }
...@@ -2422,6 +2426,7 @@ _copyDropPLangStmt(DropPLangStmt *from) ...@@ -2422,6 +2426,7 @@ _copyDropPLangStmt(DropPLangStmt *from)
if (from->plname) if (from->plname)
newnode->plname = pstrdup(from->plname); newnode->plname = pstrdup(from->plname);
newnode->behavior = from->behavior;
return newnode; return newnode;
} }
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.138 2002/06/20 20:29:29 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.139 2002/07/01 15:27:52 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -942,6 +942,8 @@ _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b) ...@@ -942,6 +942,8 @@ _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
return false; return false;
if (!equal(a->aggtype, b->aggtype)) if (!equal(a->aggtype, b->aggtype))
return false; return false;
if (a->behavior != b->behavior)
return false;
return true; return true;
} }
...@@ -953,6 +955,8 @@ _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b) ...@@ -953,6 +955,8 @@ _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
return false; return false;
if (!equal(a->args, b->args)) if (!equal(a->args, b->args))
return false; return false;
if (a->behavior != b->behavior)
return false;
return true; return true;
} }
...@@ -964,6 +968,8 @@ _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b) ...@@ -964,6 +968,8 @@ _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
return false; return false;
if (!equal(a->args, b->args)) if (!equal(a->args, b->args))
return false; return false;
if (a->behavior != b->behavior)
return false;
return true; return true;
} }
...@@ -1229,6 +1235,8 @@ _equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b) ...@@ -1229,6 +1235,8 @@ _equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b)
return false; return false;
if (a->removeType != b->removeType) if (a->removeType != b->removeType)
return false; return false;
if (a->behavior != b->behavior)
return false;
return true; return true;
} }
...@@ -1255,6 +1263,8 @@ _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b) ...@@ -1255,6 +1263,8 @@ _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
{ {
if (!equalstr(a->plname, b->plname)) if (!equalstr(a->plname, b->plname))
return false; return false;
if (a->behavior != b->behavior)
return false;
return true; return true;
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.334 2002/06/22 02:04:45 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.335 2002/07/01 15:27:55 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -112,6 +112,7 @@ static void doNegateFloat(Value *v); ...@@ -112,6 +112,7 @@ static void doNegateFloat(Value *v);
const char *keyword; const char *keyword;
bool boolean; bool boolean;
JoinType jtype; JoinType jtype;
DropBehavior dbehavior;
List *list; List *list;
Node *node; Node *node;
Value *value; Value *value;
...@@ -158,7 +159,9 @@ static void doNegateFloat(Value *v); ...@@ -158,7 +159,9 @@ static void doNegateFloat(Value *v);
simple_select simple_select
%type <node> alter_column_default %type <node> alter_column_default
%type <ival> add_drop, drop_behavior, opt_drop_behavior %type <ival> add_drop
%type <dbehavior> opt_drop_behavior
%type <list> createdb_opt_list, copy_opt_list %type <list> createdb_opt_list, copy_opt_list
%type <defelt> createdb_opt_item, copy_opt_item %type <defelt> createdb_opt_item, copy_opt_item
...@@ -594,7 +597,9 @@ AlterUserSetStmt: ...@@ -594,7 +597,9 @@ AlterUserSetStmt:
* *
* Drop a postgresql DBMS user * Drop a postgresql DBMS user
* *
* * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
* might own objects in multiple databases, there is presently no way to
* implement either cascading or restricting. Caveat DBA.
*****************************************************************************/ *****************************************************************************/
DropUserStmt: DropUserStmt:
...@@ -727,7 +732,7 @@ add_drop: ADD { $$ = +1; } ...@@ -727,7 +732,7 @@ add_drop: ADD { $$ = +1; }
* *
* Drop a postgresql group * Drop a postgresql group
* *
* * XXX see above notes about cascading DROP USER; groups have same problem.
*****************************************************************************/ *****************************************************************************/
DropGroupStmt: DropGroupStmt:
...@@ -779,7 +784,7 @@ AlterSchemaStmt: ...@@ -779,7 +784,7 @@ AlterSchemaStmt:
; ;
DropSchemaStmt: DropSchemaStmt:
DROP SCHEMA ColId DROP SCHEMA ColId opt_drop_behavior
{ {
elog(ERROR, "DROP SCHEMA not yet supported"); elog(ERROR, "DROP SCHEMA not yet supported");
} }
...@@ -1166,8 +1171,8 @@ AlterTableStmt: ...@@ -1166,8 +1171,8 @@ AlterTableStmt:
n->def = (Node *) makeString($9); n->def = (Node *) makeString($9);
$$ = (Node *)n; $$ = (Node *)n;
} }
/* ALTER TABLE <relation> DROP [COLUMN] <colname> {RESTRICT|CASCADE} */ /* ALTER TABLE <relation> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
| ALTER TABLE relation_expr DROP opt_column ColId drop_behavior | ALTER TABLE relation_expr DROP opt_column ColId opt_drop_behavior
{ {
AlterTableStmt *n = makeNode(AlterTableStmt); AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'D'; n->subtype = 'D';
...@@ -1185,8 +1190,8 @@ AlterTableStmt: ...@@ -1185,8 +1190,8 @@ AlterTableStmt:
n->def = $5; n->def = $5;
$$ = (Node *)n; $$ = (Node *)n;
} }
/* ALTER TABLE <relation> DROP CONSTRAINT <name> {RESTRICT|CASCADE} */ /* ALTER TABLE <relation> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
| ALTER TABLE relation_expr DROP CONSTRAINT name drop_behavior | ALTER TABLE relation_expr DROP CONSTRAINT name opt_drop_behavior
{ {
AlterTableStmt *n = makeNode(AlterTableStmt); AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'X'; n->subtype = 'X';
...@@ -1228,15 +1233,10 @@ alter_column_default: ...@@ -1228,15 +1233,10 @@ alter_column_default:
| DROP DEFAULT { $$ = NULL; } | DROP DEFAULT { $$ = NULL; }
; ;
drop_behavior:
CASCADE { $$ = CASCADE; }
| RESTRICT { $$ = RESTRICT; }
;
opt_drop_behavior: opt_drop_behavior:
CASCADE { $$ = CASCADE; } CASCADE { $$ = DROP_CASCADE; }
| RESTRICT { $$ = RESTRICT; } | RESTRICT { $$ = DROP_RESTRICT; }
| /* EMPTY */ { $$ = RESTRICT; /* default */ } | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
; ;
...@@ -1969,10 +1969,11 @@ opt_validator: ...@@ -1969,10 +1969,11 @@ opt_validator:
; ;
DropPLangStmt: DropPLangStmt:
DROP opt_procedural LANGUAGE ColId_or_Sconst DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
{ {
DropPLangStmt *n = makeNode(DropPLangStmt); DropPLangStmt *n = makeNode(DropPLangStmt);
n->plname = $4; n->plname = $4;
n->behavior = $5;
$$ = (Node *)n; $$ = (Node *)n;
} }
; ;
...@@ -2153,11 +2154,12 @@ ConstraintTimeSpec: ...@@ -2153,11 +2154,12 @@ ConstraintTimeSpec:
DropTrigStmt: DropTrigStmt:
DROP TRIGGER name ON qualified_name DROP TRIGGER name ON qualified_name opt_drop_behavior
{ {
DropPropertyStmt *n = makeNode(DropPropertyStmt); DropPropertyStmt *n = makeNode(DropPropertyStmt);
n->relation = $5; n->relation = $5;
n->property = $3; n->property = $3;
n->behavior = $6;
n->removeType = DROP_TRIGGER; n->removeType = DROP_TRIGGER;
$$ = (Node *) n; $$ = (Node *) n;
} }
...@@ -2190,12 +2192,13 @@ CreateAssertStmt: ...@@ -2190,12 +2192,13 @@ CreateAssertStmt:
; ;
DropAssertStmt: DropAssertStmt:
DROP ASSERTION name DROP ASSERTION name opt_drop_behavior
{ {
DropPropertyStmt *n = makeNode(DropPropertyStmt); DropPropertyStmt *n = makeNode(DropPropertyStmt);
n->relation = NULL; n->relation = NULL;
n->property = $3; n->property = $3;
n->removeType = DROP_TRIGGER; n->behavior = $4;
n->removeType = DROP_TRIGGER; /* XXX */
elog(ERROR, "DROP ASSERTION is not yet supported"); elog(ERROR, "DROP ASSERTION is not yet supported");
$$ = (Node *) n; $$ = (Node *) n;
} }
...@@ -2273,7 +2276,7 @@ def_arg: func_return { $$ = (Node *)$1; } ...@@ -2273,7 +2276,7 @@ def_arg: func_return { $$ = (Node *)$1; }
* *
* QUERY: * QUERY:
* *
* DROP itemtype itemname [, itemname ...] * DROP itemtype itemname [, itemname ...] [ RESTRICT | CASCADE ]
* *
*****************************************************************************/ *****************************************************************************/
...@@ -3111,9 +3114,9 @@ opt_assignment: AS ASSIGNMENT {} ...@@ -3111,9 +3114,9 @@ opt_assignment: AS ASSIGNMENT {}
* *
* QUERY: * QUERY:
* *
* DROP FUNCTION funcname (arg1, arg2, ...) * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
* DROP AGGREGATE aggname (aggtype) * DROP AGGREGATE aggname (aggtype) [ RESTRICT | CASCADE ]
* DROP OPERATOR opname (leftoperand_typ rightoperand_typ) * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
* *
*****************************************************************************/ *****************************************************************************/
...@@ -3123,8 +3126,7 @@ RemoveFuncStmt: ...@@ -3123,8 +3126,7 @@ RemoveFuncStmt:
RemoveFuncStmt *n = makeNode(RemoveFuncStmt); RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
n->funcname = $3; n->funcname = $3;
n->args = $4; n->args = $4;
if ($5 != RESTRICT) n->behavior = $5;
elog(ERROR, "DROP FUNCTION/CASCADE not supported");
$$ = (Node *)n; $$ = (Node *)n;
} }
| DROP CAST '(' func_type AS func_type ')' opt_drop_behavior | DROP CAST '(' func_type AS func_type ')' opt_drop_behavior
...@@ -3132,18 +3134,18 @@ RemoveFuncStmt: ...@@ -3132,18 +3134,18 @@ RemoveFuncStmt:
RemoveFuncStmt *n = makeNode(RemoveFuncStmt); RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
n->funcname = $6->names; n->funcname = $6->names;
n->args = makeList1($4); n->args = makeList1($4);
if ($8 != RESTRICT) n->behavior = $8;
elog(ERROR, "DROP CAST/CASCADE not supported");
$$ = (Node *)n; $$ = (Node *)n;
} }
; ;
RemoveAggrStmt: RemoveAggrStmt:
DROP AGGREGATE func_name '(' aggr_argtype ')' DROP AGGREGATE func_name '(' aggr_argtype ')' opt_drop_behavior
{ {
RemoveAggrStmt *n = makeNode(RemoveAggrStmt); RemoveAggrStmt *n = makeNode(RemoveAggrStmt);
n->aggname = $3; n->aggname = $3;
n->aggtype = $5; n->aggtype = $5;
n->behavior = $7;
$$ = (Node *)n; $$ = (Node *)n;
} }
; ;
...@@ -3154,11 +3156,12 @@ aggr_argtype: ...@@ -3154,11 +3156,12 @@ aggr_argtype:
; ;
RemoveOperStmt: RemoveOperStmt:
DROP OPERATOR any_operator '(' oper_argtypes ')' DROP OPERATOR any_operator '(' oper_argtypes ')' opt_drop_behavior
{ {
RemoveOperStmt *n = makeNode(RemoveOperStmt); RemoveOperStmt *n = makeNode(RemoveOperStmt);
n->opname = $3; n->opname = $3;
n->args = $5; n->args = $5;
n->behavior = $7;
$$ = (Node *)n; $$ = (Node *)n;
} }
; ;
...@@ -3335,11 +3338,12 @@ opt_instead: ...@@ -3335,11 +3338,12 @@ opt_instead:
DropRuleStmt: DropRuleStmt:
DROP RULE name ON qualified_name DROP RULE name ON qualified_name opt_drop_behavior
{ {
DropPropertyStmt *n = makeNode(DropPropertyStmt); DropPropertyStmt *n = makeNode(DropPropertyStmt);
n->relation = $5; n->relation = $5;
n->property = $3; n->property = $3;
n->behavior = $6;
n->removeType = DROP_RULE; n->removeType = DROP_RULE;
$$ = (Node *) n; $$ = (Node *) n;
} }
...@@ -3628,6 +3632,7 @@ AlterDatabaseSetStmt: ...@@ -3628,6 +3632,7 @@ AlterDatabaseSetStmt:
* *
* DROP DATABASE * DROP DATABASE
* *
* This is implicitly CASCADE, no need for drop behavior
*****************************************************************************/ *****************************************************************************/
DropdbStmt: DROP DATABASE database_name DropdbStmt: DROP DATABASE database_name
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.159 2002/06/20 20:29:36 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.160 2002/07/01 15:27:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -289,30 +289,30 @@ ProcessUtility(Node *parsetree, ...@@ -289,30 +289,30 @@ ProcessUtility(Node *parsetree,
case DROP_TABLE: case DROP_TABLE:
rel = makeRangeVarFromNameList(names); rel = makeRangeVarFromNameList(names);
CheckDropPermissions(rel, RELKIND_RELATION); CheckDropPermissions(rel, RELKIND_RELATION);
RemoveRelation(rel); RemoveRelation(rel, stmt->behavior);
break; break;
case DROP_SEQUENCE: case DROP_SEQUENCE:
rel = makeRangeVarFromNameList(names); rel = makeRangeVarFromNameList(names);
CheckDropPermissions(rel, RELKIND_SEQUENCE); CheckDropPermissions(rel, RELKIND_SEQUENCE);
RemoveRelation(rel); RemoveRelation(rel, stmt->behavior);
break; break;
case DROP_VIEW: case DROP_VIEW:
rel = makeRangeVarFromNameList(names); rel = makeRangeVarFromNameList(names);
CheckDropPermissions(rel, RELKIND_VIEW); CheckDropPermissions(rel, RELKIND_VIEW);
RemoveView(rel); RemoveView(rel, stmt->behavior);
break; break;
case DROP_INDEX: case DROP_INDEX:
rel = makeRangeVarFromNameList(names); rel = makeRangeVarFromNameList(names);
CheckDropPermissions(rel, RELKIND_INDEX); CheckDropPermissions(rel, RELKIND_INDEX);
RemoveIndex(rel); RemoveIndex(rel, stmt->behavior);
break; break;
case DROP_TYPE: case DROP_TYPE:
/* RemoveType does its own permissions checks */ /* RemoveType does its own permissions checks */
RemoveType(names); RemoveType(names, stmt->behavior);
break; break;
case DROP_DOMAIN: case DROP_DOMAIN:
...@@ -606,24 +606,15 @@ ProcessUtility(Node *parsetree, ...@@ -606,24 +606,15 @@ ProcessUtility(Node *parsetree,
break; break;
case T_RemoveOperStmt: case T_RemoveOperStmt:
{ RemoveOperator((RemoveOperStmt *) parsetree);
RemoveOperStmt *stmt = (RemoveOperStmt *) parsetree;
TypeName *typenode1 = (TypeName *) lfirst(stmt->args);
TypeName *typenode2 = (TypeName *) lsecond(stmt->args);
RemoveOperator(stmt->opname, typenode1, typenode2);
}
break; break;
case T_CreatedbStmt: case T_CreatedbStmt:
{ createdb((CreatedbStmt *) parsetree);
CreatedbStmt *stmt = (CreatedbStmt *) parsetree;
createdb(stmt);
}
break; break;
case T_AlterDatabaseSetStmt: case T_AlterDatabaseSetStmt:
AlterDatabaseSet((AlterDatabaseSetStmt *)parsetree); AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
break; break;
case T_DropdbStmt: case T_DropdbStmt:
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: defrem.h,v 1.39 2002/06/20 20:29:49 momjian Exp $ * $Id: defrem.h,v 1.40 2002/07/01 15:27:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -29,7 +29,7 @@ extern void DefineIndex(RangeVar *heapRelation, ...@@ -29,7 +29,7 @@ extern void DefineIndex(RangeVar *heapRelation,
bool primary, bool primary,
Expr *predicate, Expr *predicate,
List *rangetable); List *rangetable);
extern void RemoveIndex(RangeVar *relation); extern void RemoveIndex(RangeVar *relation, DropBehavior behavior);
extern void ReindexIndex(RangeVar *indexRelation, bool force); extern void ReindexIndex(RangeVar *indexRelation, bool force);
extern void ReindexTable(RangeVar *relation, bool force); extern void ReindexTable(RangeVar *relation, bool force);
extern void ReindexDatabase(const char *databaseName, bool force, bool all); extern void ReindexDatabase(const char *databaseName, bool force, bool all);
...@@ -42,16 +42,15 @@ extern void CreateFunction(CreateFunctionStmt *stmt); ...@@ -42,16 +42,15 @@ extern void CreateFunction(CreateFunctionStmt *stmt);
extern void RemoveFunction(List *functionName, List *argTypes); extern void RemoveFunction(List *functionName, List *argTypes);
extern void DefineOperator(List *names, List *parameters); extern void DefineOperator(List *names, List *parameters);
extern void RemoveOperator(List *operatorName, extern void RemoveOperator(RemoveOperStmt *stmt);
TypeName *typeName1, TypeName *typeName2);
extern void DefineAggregate(List *names, List *parameters); extern void DefineAggregate(List *names, List *parameters);
extern void RemoveAggregate(List *aggName, TypeName *aggType); extern void RemoveAggregate(List *aggName, TypeName *aggType);
extern void DefineType(List *names, List *parameters); extern void DefineType(List *names, List *parameters);
extern void RemoveType(List *names); extern void RemoveType(List *names, DropBehavior behavior);
extern void DefineDomain(CreateDomainStmt *stmt); extern void DefineDomain(CreateDomainStmt *stmt);
extern void RemoveDomain(List *names, int behavior); extern void RemoveDomain(List *names, DropBehavior behavior);
/* support routines in commands/define.c */ /* support routines in commands/define.c */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: tablecmds.h,v 1.4 2002/04/30 01:24:52 tgl Exp $ * $Id: tablecmds.h,v 1.5 2002/07/01 15:27:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -34,13 +34,15 @@ extern void AlterTableAlterColumnFlags(Oid myrelid, bool inh, ...@@ -34,13 +34,15 @@ extern void AlterTableAlterColumnFlags(Oid myrelid, bool inh,
Node *flagValue, const char *flagType); Node *flagValue, const char *flagType);
extern void AlterTableDropColumn(Oid myrelid, bool inh, extern void AlterTableDropColumn(Oid myrelid, bool inh,
const char *colName, int behavior); const char *colName,
DropBehavior behavior);
extern void AlterTableAddConstraint(Oid myrelid, bool inh, extern void AlterTableAddConstraint(Oid myrelid, bool inh,
List *newConstraints); List *newConstraints);
extern void AlterTableDropConstraint(Oid myrelid, bool inh, extern void AlterTableDropConstraint(Oid myrelid, bool inh,
const char *constrName, int behavior); const char *constrName,
DropBehavior behavior);
extern void AlterTableCreateToastTable(Oid relOid, bool silent); extern void AlterTableCreateToastTable(Oid relOid, bool silent);
...@@ -48,7 +50,7 @@ extern void AlterTableOwner(Oid relationOid, int32 newOwnerSysId); ...@@ -48,7 +50,7 @@ extern void AlterTableOwner(Oid relationOid, int32 newOwnerSysId);
extern Oid DefineRelation(CreateStmt *stmt, char relkind); extern Oid DefineRelation(CreateStmt *stmt, char relkind);
extern void RemoveRelation(const RangeVar *relation); extern void RemoveRelation(const RangeVar *relation, DropBehavior behavior);
extern void TruncateRelation(const RangeVar *relation); extern void TruncateRelation(const RangeVar *relation);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: view.h,v 1.15 2002/06/20 20:29:49 momjian Exp $ * $Id: view.h,v 1.16 2002/07/01 15:27:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -17,6 +17,6 @@ ...@@ -17,6 +17,6 @@
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
extern void DefineView(const RangeVar *view, Query *view_parse); extern void DefineView(const RangeVar *view, Query *view_parse);
extern void RemoveView(const RangeVar *view); extern void RemoveView(const RangeVar *view, DropBehavior behavior);
#endif /* VIEW_H */ #endif /* VIEW_H */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: parsenodes.h,v 1.182 2002/06/20 20:29:51 momjian Exp $ * $Id: parsenodes.h,v 1.183 2002/07/01 15:27:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -737,6 +737,12 @@ typedef struct CreateSchemaStmt ...@@ -737,6 +737,12 @@ typedef struct CreateSchemaStmt
List *schemaElts; /* schema components (list of parsenodes) */ List *schemaElts; /* schema components (list of parsenodes) */
} CreateSchemaStmt; } CreateSchemaStmt;
typedef enum DropBehavior
{
DROP_RESTRICT, /* drop fails if any dependent objects */
DROP_CASCADE /* remove dependent objects too */
} DropBehavior;
/* ---------------------- /* ----------------------
* Alter Table * Alter Table
* *
...@@ -765,7 +771,7 @@ typedef struct AlterTableStmt ...@@ -765,7 +771,7 @@ typedef struct AlterTableStmt
char *name; /* column or constraint name to act on, or char *name; /* column or constraint name to act on, or
* new owner */ * new owner */
Node *def; /* definition of new column or constraint */ Node *def; /* definition of new column or constraint */
int behavior; /* CASCADE or RESTRICT drop behavior */ DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
} AlterTableStmt; } AlterTableStmt;
/* ---------------------- /* ----------------------
...@@ -996,6 +1002,7 @@ typedef struct DropPLangStmt ...@@ -996,6 +1002,7 @@ typedef struct DropPLangStmt
{ {
NodeTag type; NodeTag type;
char *plname; /* PL name */ char *plname; /* PL name */
DropBehavior behavior; /* RESTRICT or CASCADE behavior */
} DropPLangStmt; } DropPLangStmt;
/* ---------------------- /* ----------------------
...@@ -1107,8 +1114,8 @@ typedef struct DropStmt ...@@ -1107,8 +1114,8 @@ typedef struct DropStmt
{ {
NodeTag type; NodeTag type;
List *objects; /* list of sublists of names (as Values) */ List *objects; /* list of sublists of names (as Values) */
int removeType; int removeType; /* see #defines above */
int behavior; /* CASCADE or RESTRICT drop behavior */ DropBehavior behavior; /* RESTRICT or CASCADE behavior */
} DropStmt; } DropStmt;
/* ---------------------- /* ----------------------
...@@ -1127,7 +1134,8 @@ typedef struct DropPropertyStmt ...@@ -1127,7 +1134,8 @@ typedef struct DropPropertyStmt
NodeTag type; NodeTag type;
RangeVar *relation; /* owning relation */ RangeVar *relation; /* owning relation */
char *property; /* name of rule, trigger, etc */ char *property; /* name of rule, trigger, etc */
int removeType; int removeType; /* see #defines above */
DropBehavior behavior; /* RESTRICT or CASCADE behavior */
} DropPropertyStmt; } DropPropertyStmt;
/* ---------------------- /* ----------------------
...@@ -1218,6 +1226,7 @@ typedef struct RemoveAggrStmt ...@@ -1218,6 +1226,7 @@ typedef struct RemoveAggrStmt
NodeTag type; NodeTag type;
List *aggname; /* aggregate to drop */ List *aggname; /* aggregate to drop */
TypeName *aggtype; /* TypeName for input datatype, or NULL */ TypeName *aggtype; /* TypeName for input datatype, or NULL */
DropBehavior behavior; /* RESTRICT or CASCADE behavior */
} RemoveAggrStmt; } RemoveAggrStmt;
/* ---------------------- /* ----------------------
...@@ -1229,6 +1238,7 @@ typedef struct RemoveFuncStmt ...@@ -1229,6 +1238,7 @@ typedef struct RemoveFuncStmt
NodeTag type; NodeTag type;
List *funcname; /* function to drop */ List *funcname; /* function to drop */
List *args; /* types of the arguments */ List *args; /* types of the arguments */
DropBehavior behavior; /* RESTRICT or CASCADE behavior */
} RemoveFuncStmt; } RemoveFuncStmt;
/* ---------------------- /* ----------------------
...@@ -1240,6 +1250,7 @@ typedef struct RemoveOperStmt ...@@ -1240,6 +1250,7 @@ typedef struct RemoveOperStmt
NodeTag type; NodeTag type;
List *opname; /* operator to drop */ List *opname; /* operator to drop */
List *args; /* types of the arguments */ List *args; /* types of the arguments */
DropBehavior behavior; /* RESTRICT or CASCADE behavior */
} RemoveOperStmt; } RemoveOperStmt;
/* ---------------------- /* ----------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment