*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
/*
* RemoveIndex
* Deletes an index.
- *
- * Exceptions:
- * BadArg if name is invalid.
- * "ERROR" if index nonexistent.
- * ...
*/
void
-RemoveIndex(RangeVar *relation)
+RemoveIndex(RangeVar *relation, DropBehavior behavior)
{
Oid indOid;
HeapTuple tuple;
*
*
* 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
* The "DefineFoo" routines take the parse tree and pick out the
/*
* RemoveOperator
* Deletes an operator.
- *
- * Exceptions:
- * BadArg if name is invalid.
- * BadArg if type1 is invalid.
- * "ERROR" if operator nonexistent.
- * ...
*/
void
-RemoveOperator(List *operatorName, /* operator name */
- TypeName *typeName1, /* left argument type name */
- TypeName *typeName2) /* right argument type name */
+RemoveOperator(RemoveOperStmt *stmt)
{
+ List *operatorName = stmt->opname;
+ TypeName *typeName1 = (TypeName *) lfirst(stmt->args);
+ TypeName *typeName2 = (TypeName *) lsecond(stmt->args);
Oid operOid;
Relation relation;
HeapTuple tup;
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#include "optimizer/clauses.h"
#include "optimizer/planmain.h"
#include "optimizer/prep.h"
-#include "parser/parse.h"
#include "parser/parse_coerce.h"
#include "parser/parse_expr.h"
#include "parser/parse_relation.h"
* themselves will be destroyed, too.
*/
void
-RemoveRelation(const RangeVar *relation)
+RemoveRelation(const RangeVar *relation, DropBehavior behavior)
{
Oid relOid;
void
AlterTableDropColumn(Oid myrelid,
bool inh, const char *colName,
- int behavior)
+ DropBehavior behavior)
{
elog(ERROR, "ALTER TABLE / DROP COLUMN is not implemented");
}
void
AlterTableDropConstraint(Oid myrelid,
bool inh, const char *constrName,
- int behavior)
+ DropBehavior behavior)
{
Relation rel;
int deleted;
* We don't support CASCADE yet - in fact, RESTRICT doesn't work to
* the spec either!
*/
- if (behavior == CASCADE)
+ if (behavior == DROP_CASCADE)
elog(ERROR, "ALTER TABLE / DROP CONSTRAINT does not support the CASCADE keyword");
/*
*
*
* 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
* The "DefineFoo" routines take the parse tree and pick out the
#include "commands/comment.h"
#include "commands/defrem.h"
#include "miscadmin.h"
-#include "parser/parse.h"
#include "parser/parse_func.h"
#include "parser/parse_type.h"
#include "utils/acl.h"
* only work on scalar types.
*/
void
-RemoveType(List *names)
+RemoveType(List *names, DropBehavior behavior)
{
TypeName *typename;
Relation relation;
* Removes a domain.
*/
void
-RemoveDomain(List *names, int behavior)
+RemoveDomain(List *names, DropBehavior behavior)
{
TypeName *typename;
Relation relation;
char typtype;
/* CASCADE unsupported */
- if (behavior == CASCADE)
+ if (behavior == DROP_CASCADE)
elog(ERROR, "DROP DOMAIN does not support the CASCADE keyword");
/* Make a TypeName so we can use standard type lookup machinery */
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* 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 $
*
*-------------------------------------------------------------------------
*/
DefineViewRules(view, viewParse);
}
-/*------------------------------------------------------------------
+/*
* RemoveView
*
* Remove a view given its name
- *------------------------------------------------------------------
*/
void
-RemoveView(const RangeVar *view)
+RemoveView(const RangeVar *view, DropBehavior behavior)
{
Oid viewOid;
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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 $
*
*-------------------------------------------------------------------------
*/
Node_Copy(from, newnode, aggname);
Node_Copy(from, newnode, aggtype);
+ newnode->behavior = from->behavior;
return newnode;
}
Node_Copy(from, newnode, funcname);
Node_Copy(from, newnode, args);
+ newnode->behavior = from->behavior;
return newnode;
}
Node_Copy(from, newnode, opname);
Node_Copy(from, newnode, args);
+ newnode->behavior = from->behavior;
return newnode;
}
if (from->property)
newnode->property = pstrdup(from->property);
newnode->removeType = from->removeType;
+ newnode->behavior = from->behavior;
return newnode;
}
if (from->plname)
newnode->plname = pstrdup(from->plname);
+ newnode->behavior = from->behavior;
return newnode;
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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 $
*
*-------------------------------------------------------------------------
*/
return false;
if (!equal(a->aggtype, b->aggtype))
return false;
+ if (a->behavior != b->behavior)
+ return false;
return true;
}
return false;
if (!equal(a->args, b->args))
return false;
+ if (a->behavior != b->behavior)
+ return false;
return true;
}
return false;
if (!equal(a->args, b->args))
return false;
+ if (a->behavior != b->behavior)
+ return false;
return true;
}
return false;
if (a->removeType != b->removeType)
return false;
+ if (a->behavior != b->behavior)
+ return false;
return true;
}
{
if (!equalstr(a->plname, b->plname))
return false;
+ if (a->behavior != b->behavior)
+ return false;
return true;
}
*
*
* 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
* AUTHOR DATE MAJOR EVENT
const char *keyword;
bool boolean;
JoinType jtype;
+ DropBehavior dbehavior;
List *list;
Node *node;
Value *value;
simple_select
%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 <defelt> createdb_opt_item, copy_opt_item
*
* 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:
*
* Drop a postgresql group
*
- *
+ * XXX see above notes about cascading DROP USER; groups have same problem.
*****************************************************************************/
DropGroupStmt:
;
DropSchemaStmt:
- DROP SCHEMA ColId
+ DROP SCHEMA ColId opt_drop_behavior
{
elog(ERROR, "DROP SCHEMA not yet supported");
}
n->def = (Node *) makeString($9);
$$ = (Node *)n;
}
- /* ALTER TABLE <relation> DROP [COLUMN] <colname> {RESTRICT|CASCADE} */
- | ALTER TABLE relation_expr DROP opt_column ColId drop_behavior
+ /* ALTER TABLE <relation> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
+ | ALTER TABLE relation_expr DROP opt_column ColId opt_drop_behavior
{
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'D';
n->def = $5;
$$ = (Node *)n;
}
- /* ALTER TABLE <relation> DROP CONSTRAINT <name> {RESTRICT|CASCADE} */
- | ALTER TABLE relation_expr DROP CONSTRAINT name drop_behavior
+ /* ALTER TABLE <relation> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
+ | ALTER TABLE relation_expr DROP CONSTRAINT name opt_drop_behavior
{
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'X';
| DROP DEFAULT { $$ = NULL; }
;
-drop_behavior:
- CASCADE { $$ = CASCADE; }
- | RESTRICT { $$ = RESTRICT; }
- ;
-
opt_drop_behavior:
- CASCADE { $$ = CASCADE; }
- | RESTRICT { $$ = RESTRICT; }
- | /* EMPTY */ { $$ = RESTRICT; /* default */ }
+ CASCADE { $$ = DROP_CASCADE; }
+ | RESTRICT { $$ = DROP_RESTRICT; }
+ | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
;
;
DropPLangStmt:
- DROP opt_procedural LANGUAGE ColId_or_Sconst
+ DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
{
DropPLangStmt *n = makeNode(DropPLangStmt);
n->plname = $4;
+ n->behavior = $5;
$$ = (Node *)n;
}
;
DropTrigStmt:
- DROP TRIGGER name ON qualified_name
+ DROP TRIGGER name ON qualified_name opt_drop_behavior
{
DropPropertyStmt *n = makeNode(DropPropertyStmt);
n->relation = $5;
n->property = $3;
+ n->behavior = $6;
n->removeType = DROP_TRIGGER;
$$ = (Node *) n;
}
;
DropAssertStmt:
- DROP ASSERTION name
+ DROP ASSERTION name opt_drop_behavior
{
DropPropertyStmt *n = makeNode(DropPropertyStmt);
n->relation = NULL;
n->property = $3;
- n->removeType = DROP_TRIGGER;
+ n->behavior = $4;
+ n->removeType = DROP_TRIGGER; /* XXX */
elog(ERROR, "DROP ASSERTION is not yet supported");
$$ = (Node *) n;
}
*
* QUERY:
*
- * DROP itemtype itemname [, itemname ...]
+ * DROP itemtype itemname [, itemname ...] [ RESTRICT | CASCADE ]
*
*****************************************************************************/
*
* QUERY:
*
- * DROP FUNCTION funcname (arg1, arg2, ...)
- * DROP AGGREGATE aggname (aggtype)
- * DROP OPERATOR opname (leftoperand_typ rightoperand_typ)
+ * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
+ * DROP AGGREGATE aggname (aggtype) [ RESTRICT | CASCADE ]
+ * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
*
*****************************************************************************/
RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
n->funcname = $3;
n->args = $4;
- if ($5 != RESTRICT)
- elog(ERROR, "DROP FUNCTION/CASCADE not supported");
+ n->behavior = $5;
$$ = (Node *)n;
}
| DROP CAST '(' func_type AS func_type ')' opt_drop_behavior
RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
n->funcname = $6->names;
n->args = makeList1($4);
- if ($8 != RESTRICT)
- elog(ERROR, "DROP CAST/CASCADE not supported");
+ n->behavior = $8;
$$ = (Node *)n;
}
;
RemoveAggrStmt:
- DROP AGGREGATE func_name '(' aggr_argtype ')'
+ DROP AGGREGATE func_name '(' aggr_argtype ')' opt_drop_behavior
{
RemoveAggrStmt *n = makeNode(RemoveAggrStmt);
n->aggname = $3;
n->aggtype = $5;
+ n->behavior = $7;
$$ = (Node *)n;
}
;
;
RemoveOperStmt:
- DROP OPERATOR any_operator '(' oper_argtypes ')'
+ DROP OPERATOR any_operator '(' oper_argtypes ')' opt_drop_behavior
{
RemoveOperStmt *n = makeNode(RemoveOperStmt);
n->opname = $3;
n->args = $5;
+ n->behavior = $7;
$$ = (Node *)n;
}
;
DropRuleStmt:
- DROP RULE name ON qualified_name
+ DROP RULE name ON qualified_name opt_drop_behavior
{
DropPropertyStmt *n = makeNode(DropPropertyStmt);
n->relation = $5;
n->property = $3;
+ n->behavior = $6;
n->removeType = DROP_RULE;
$$ = (Node *) n;
}
*
* DROP DATABASE
*
+ * This is implicitly CASCADE, no need for drop behavior
*****************************************************************************/
DropdbStmt: DROP DATABASE database_name
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
case DROP_TABLE:
rel = makeRangeVarFromNameList(names);
CheckDropPermissions(rel, RELKIND_RELATION);
- RemoveRelation(rel);
+ RemoveRelation(rel, stmt->behavior);
break;
case DROP_SEQUENCE:
rel = makeRangeVarFromNameList(names);
CheckDropPermissions(rel, RELKIND_SEQUENCE);
- RemoveRelation(rel);
+ RemoveRelation(rel, stmt->behavior);
break;
case DROP_VIEW:
rel = makeRangeVarFromNameList(names);
CheckDropPermissions(rel, RELKIND_VIEW);
- RemoveView(rel);
+ RemoveView(rel, stmt->behavior);
break;
case DROP_INDEX:
rel = makeRangeVarFromNameList(names);
CheckDropPermissions(rel, RELKIND_INDEX);
- RemoveIndex(rel);
+ RemoveIndex(rel, stmt->behavior);
break;
case DROP_TYPE:
/* RemoveType does its own permissions checks */
- RemoveType(names);
+ RemoveType(names, stmt->behavior);
break;
case DROP_DOMAIN:
break;
case T_RemoveOperStmt:
- {
- RemoveOperStmt *stmt = (RemoveOperStmt *) parsetree;
- TypeName *typenode1 = (TypeName *) lfirst(stmt->args);
- TypeName *typenode2 = (TypeName *) lsecond(stmt->args);
-
- RemoveOperator(stmt->opname, typenode1, typenode2);
- }
+ RemoveOperator((RemoveOperStmt *) parsetree);
break;
case T_CreatedbStmt:
- {
- CreatedbStmt *stmt = (CreatedbStmt *) parsetree;
- createdb(stmt);
- }
+ createdb((CreatedbStmt *) parsetree);
break;
case T_AlterDatabaseSetStmt:
- AlterDatabaseSet((AlterDatabaseSetStmt *)parsetree);
+ AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
break;
case T_DropdbStmt:
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* 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 $
*
*-------------------------------------------------------------------------
*/
bool primary,
Expr *predicate,
List *rangetable);
-extern void RemoveIndex(RangeVar *relation);
+extern void RemoveIndex(RangeVar *relation, DropBehavior behavior);
extern void ReindexIndex(RangeVar *indexRelation, bool force);
extern void ReindexTable(RangeVar *relation, bool force);
extern void ReindexDatabase(const char *databaseName, bool force, bool all);
extern void RemoveFunction(List *functionName, List *argTypes);
extern void DefineOperator(List *names, List *parameters);
-extern void RemoveOperator(List *operatorName,
- TypeName *typeName1, TypeName *typeName2);
+extern void RemoveOperator(RemoveOperStmt *stmt);
extern void DefineAggregate(List *names, List *parameters);
extern void RemoveAggregate(List *aggName, TypeName *aggType);
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 RemoveDomain(List *names, int behavior);
+extern void RemoveDomain(List *names, DropBehavior behavior);
/* support routines in commands/define.c */
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* 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 $
*
*-------------------------------------------------------------------------
*/
Node *flagValue, const char *flagType);
extern void AlterTableDropColumn(Oid myrelid, bool inh,
- const char *colName, int behavior);
+ const char *colName,
+ DropBehavior behavior);
extern void AlterTableAddConstraint(Oid myrelid, bool inh,
List *newConstraints);
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 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);
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* 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 $
*
*-------------------------------------------------------------------------
*/
#include "nodes/parsenodes.h"
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 */
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* 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 $
*
*-------------------------------------------------------------------------
*/
List *schemaElts; /* schema components (list of parsenodes) */
} CreateSchemaStmt;
+typedef enum DropBehavior
+{
+ DROP_RESTRICT, /* drop fails if any dependent objects */
+ DROP_CASCADE /* remove dependent objects too */
+} DropBehavior;
+
/* ----------------------
* Alter Table
*
char *name; /* column or constraint name to act on, or
* new owner */
Node *def; /* definition of new column or constraint */
- int behavior; /* CASCADE or RESTRICT drop behavior */
+ DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
} AlterTableStmt;
/* ----------------------
{
NodeTag type;
char *plname; /* PL name */
+ DropBehavior behavior; /* RESTRICT or CASCADE behavior */
} DropPLangStmt;
/* ----------------------
{
NodeTag type;
List *objects; /* list of sublists of names (as Values) */
- int removeType;
- int behavior; /* CASCADE or RESTRICT drop behavior */
+ int removeType; /* see #defines above */
+ DropBehavior behavior; /* RESTRICT or CASCADE behavior */
} DropStmt;
/* ----------------------
NodeTag type;
RangeVar *relation; /* owning relation */
char *property; /* name of rule, trigger, etc */
- int removeType;
+ int removeType; /* see #defines above */
+ DropBehavior behavior; /* RESTRICT or CASCADE behavior */
} DropPropertyStmt;
/* ----------------------
NodeTag type;
List *aggname; /* aggregate to drop */
TypeName *aggtype; /* TypeName for input datatype, or NULL */
+ DropBehavior behavior; /* RESTRICT or CASCADE behavior */
} RemoveAggrStmt;
/* ----------------------
NodeTag type;
List *funcname; /* function to drop */
List *args; /* types of the arguments */
+ DropBehavior behavior; /* RESTRICT or CASCADE behavior */
} RemoveFuncStmt;
/* ----------------------
NodeTag type;
List *opname; /* operator to drop */
List *args; /* types of the arguments */
+ DropBehavior behavior; /* RESTRICT or CASCADE behavior */
} RemoveOperStmt;
/* ----------------------