First phase of applying Rod Taylor's pg_depend patch. This just adds
authorTom Lane
Mon, 1 Jul 2002 15:27:56 +0000 (15:27 +0000)
committerTom Lane
Mon, 1 Jul 2002 15:27:56 +0000 (15:27 +0000)
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.

13 files changed:
src/backend/commands/indexcmds.c
src/backend/commands/operatorcmds.c
src/backend/commands/tablecmds.c
src/backend/commands/typecmds.c
src/backend/commands/view.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/parser/gram.y
src/backend/tcop/utility.c
src/include/commands/defrem.h
src/include/commands/tablecmds.h
src/include/commands/view.h
src/include/nodes/parsenodes.h

index 3a1519a50072a70d87db695f25e62d60a931ccb9..1338f16bb59b5236a21e964915e51c17703b0b19 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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)
 /*
  * 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;
index de8ec06acbfe8cc487d48cb4e6ef21b9702ec511..fcf96c5e9c17d58c3ce29ebde573cdeb5443eb4e 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * 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
@@ -209,18 +209,13 @@ DefineOperator(List *names, List *parameters)
 /*
  * 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;
index 3bcf774ba29e359ad0ad9520544572e96a6d073f..b92bf4bba166bfcae45ebfa6e5cac9c2914f3655 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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 @@
 #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"
@@ -280,7 +279,7 @@ DefineRelation(CreateStmt *stmt, char relkind)
  * themselves will be destroyed, too.
  */
 void
-RemoveRelation(const RangeVar *relation)
+RemoveRelation(const RangeVar *relation, DropBehavior behavior)
 {
    Oid         relOid;
 
@@ -2336,7 +2335,7 @@ AlterTableAlterColumnFlags(Oid myrelid,
 void
 AlterTableDropColumn(Oid myrelid,
                     bool inh, const char *colName,
-                    int behavior)
+                    DropBehavior behavior)
 {
    elog(ERROR, "ALTER TABLE / DROP COLUMN is not implemented");
 }
@@ -2669,7 +2668,7 @@ AlterTableAddConstraint(Oid myrelid,
 void
 AlterTableDropConstraint(Oid myrelid,
                         bool inh, const char *constrName,
-                        int behavior)
+                        DropBehavior behavior)
 {
    Relation    rel;
    int         deleted;
@@ -2678,7 +2677,7 @@ AlterTableDropConstraint(Oid myrelid,
     * 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");
 
    /*
index 6aa5fae182e2ba938a9e3b5fb63182660b3cb0e6..a9b468558107807c82b37e4466db8cf2c59465a9 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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
@@ -39,7 +39,6 @@
 #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"
@@ -268,7 +267,7 @@ DefineType(List *names, List *parameters)
  * only work on scalar types.
  */
 void
-RemoveType(List *names)
+RemoveType(List *names, DropBehavior behavior)
 {
    TypeName   *typename;
    Relation    relation;
@@ -574,7 +573,7 @@ DefineDomain(CreateDomainStmt *stmt)
  *     Removes a domain.
  */
 void
-RemoveDomain(List *names, int behavior)
+RemoveDomain(List *names, DropBehavior behavior)
 {
    TypeName   *typename;
    Relation    relation;
@@ -583,7 +582,7 @@ RemoveDomain(List *names, int behavior)
    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 */
index e21b72a87a52eaff2a05571ca08e75205fa5e99e..d27350fd4677d11b288ced85e3697b251f8aa674 100644 (file)
@@ -6,7 +6,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -248,14 +248,13 @@ DefineView(const RangeVar *view, Query *viewParse)
    DefineViewRules(view, viewParse);
 }
 
-/*------------------------------------------------------------------
+/*
  * RemoveView
  *
  * Remove a view given its name
- *------------------------------------------------------------------
  */
 void
-RemoveView(const RangeVar *view)
+RemoveView(const RangeVar *view, DropBehavior behavior)
 {
    Oid         viewOid;
 
index 6c1564dc5a3f6fe5be37dd4c89d1b16846df7a84..739161b17919f3f88318e7c11ccd4ee46e645198 100644 (file)
@@ -15,7 +15,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -2115,6 +2115,7 @@ _copyRemoveAggrStmt(RemoveAggrStmt *from)
 
    Node_Copy(from, newnode, aggname);
    Node_Copy(from, newnode, aggtype);
+   newnode->behavior = from->behavior;
 
    return newnode;
 }
@@ -2126,6 +2127,7 @@ _copyRemoveFuncStmt(RemoveFuncStmt *from)
 
    Node_Copy(from, newnode, funcname);
    Node_Copy(from, newnode, args);
+   newnode->behavior = from->behavior;
 
    return newnode;
 }
@@ -2137,6 +2139,7 @@ _copyRemoveOperStmt(RemoveOperStmt *from)
 
    Node_Copy(from, newnode, opname);
    Node_Copy(from, newnode, args);
+   newnode->behavior = from->behavior;
 
    return newnode;
 }
@@ -2395,6 +2398,7 @@ _copyDropPropertyStmt(DropPropertyStmt *from)
    if (from->property)
        newnode->property = pstrdup(from->property);
    newnode->removeType = from->removeType;
+   newnode->behavior = from->behavior;
 
    return newnode;
 }
@@ -2422,6 +2426,7 @@ _copyDropPLangStmt(DropPLangStmt *from)
 
    if (from->plname)
        newnode->plname = pstrdup(from->plname);
+   newnode->behavior = from->behavior;
 
    return newnode;
 }
index 558abc00c7e45153785df59f0364c52273161e10..214493449b96c9ab678be81d0f2fb3ac5af84eaf 100644 (file)
@@ -20,7 +20,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -942,6 +942,8 @@ _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
        return false;
    if (!equal(a->aggtype, b->aggtype))
        return false;
+   if (a->behavior != b->behavior)
+       return false;
 
    return true;
 }
@@ -953,6 +955,8 @@ _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
        return false;
    if (!equal(a->args, b->args))
        return false;
+   if (a->behavior != b->behavior)
+       return false;
 
    return true;
 }
@@ -964,6 +968,8 @@ _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
        return false;
    if (!equal(a->args, b->args))
        return false;
+   if (a->behavior != b->behavior)
+       return false;
 
    return true;
 }
@@ -1229,6 +1235,8 @@ _equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b)
        return false;
    if (a->removeType != b->removeType)
        return false;
+   if (a->behavior != b->behavior)
+       return false;
 
    return true;
 }
@@ -1255,6 +1263,8 @@ _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
 {
    if (!equalstr(a->plname, b->plname))
        return false;
+   if (a->behavior != b->behavior)
+       return false;
 
    return true;
 }
index 65d0503ed7945dece6ba404358120dcbd1bec0e5..f73b4552b84e9b8d132dea98055ee56c60ca6e11 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * 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
@@ -112,6 +112,7 @@ static void doNegateFloat(Value *v);
    const char          *keyword;
    bool                boolean;
    JoinType            jtype;
+   DropBehavior        dbehavior;
    List                *list;
    Node                *node;
    Value               *value;
@@ -158,7 +159,9 @@ static void doNegateFloat(Value *v);
                simple_select
 
 %type    alter_column_default
-%type    add_drop, drop_behavior, opt_drop_behavior
+%type    add_drop
+
+%type   opt_drop_behavior
 
 %type    createdb_opt_list, copy_opt_list
 %type  createdb_opt_item, copy_opt_item
@@ -594,7 +597,9 @@ AlterUserSetStmt:
  *
  * 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:
@@ -727,7 +732,7 @@ add_drop:   ADD                                     { $$ = +1; }
  *
  * Drop a postgresql group
  *
- *
+ * XXX see above notes about cascading DROP USER; groups have same problem.
  *****************************************************************************/
 
 DropGroupStmt:
@@ -779,7 +784,7 @@ AlterSchemaStmt:
        ;
 
 DropSchemaStmt:
-           DROP SCHEMA ColId
+           DROP SCHEMA ColId opt_drop_behavior
                {
                    elog(ERROR, "DROP SCHEMA not yet supported");
                }
@@ -1166,8 +1171,8 @@ AlterTableStmt:
                    n->def = (Node *) makeString($9);
                    $$ = (Node *)n;
                }
-           /* ALTER TABLE  DROP [COLUMN]  {RESTRICT|CASCADE} */
-           | ALTER TABLE relation_expr DROP opt_column ColId drop_behavior
+           /* ALTER TABLE  DROP [COLUMN]  [RESTRICT|CASCADE] */
+           | ALTER TABLE relation_expr DROP opt_column ColId opt_drop_behavior
                {
                    AlterTableStmt *n = makeNode(AlterTableStmt);
                    n->subtype = 'D';
@@ -1185,8 +1190,8 @@ AlterTableStmt:
                    n->def = $5;
                    $$ = (Node *)n;
                }
-           /* ALTER TABLE  DROP CONSTRAINT  {RESTRICT|CASCADE} */
-           | ALTER TABLE relation_expr DROP CONSTRAINT name drop_behavior
+           /* ALTER TABLE  DROP CONSTRAINT  [RESTRICT|CASCADE] */
+           | ALTER TABLE relation_expr DROP CONSTRAINT name opt_drop_behavior
                {
                    AlterTableStmt *n = makeNode(AlterTableStmt);
                    n->subtype = 'X';
@@ -1228,15 +1233,10 @@ alter_column_default:
            | 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 */ }
        ;
 
 
@@ -1969,10 +1969,11 @@ opt_validator:
        ;
 
 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;
                }
        ;
@@ -2153,11 +2154,12 @@ ConstraintTimeSpec:
 
 
 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;
                }
@@ -2190,12 +2192,13 @@ CreateAssertStmt:
        ;
 
 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;
                }
@@ -2273,7 +2276,7 @@ def_arg:  func_return                     { $$ = (Node *)$1; }
  *
  *     QUERY:
  *
- *     DROP itemtype itemname [, itemname ...]
+ *     DROP itemtype itemname [, itemname ...] [ RESTRICT | CASCADE ]
  *
  *****************************************************************************/
 
@@ -3111,9 +3114,9 @@ opt_assignment:  AS ASSIGNMENT                    {}
  *
  *     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 ]
  *
  *****************************************************************************/
 
@@ -3123,8 +3126,7 @@ RemoveFuncStmt:
                    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
@@ -3132,18 +3134,18 @@ RemoveFuncStmt:
                    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;
                }
        ;
@@ -3154,11 +3156,12 @@ aggr_argtype:
        ;
 
 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;
                }
        ;
@@ -3335,11 +3338,12 @@ opt_instead:
 
 
 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;
                }
@@ -3628,6 +3632,7 @@ AlterDatabaseSetStmt:
  *
  *     DROP DATABASE
  *
+ * This is implicitly CASCADE, no need for drop behavior
  *****************************************************************************/
 
 DropdbStmt: DROP DATABASE database_name
index 8277a165791f54b372c7f07abafd30217b701e5a..f5c38d071ed74db1e815955f86abd65e5b7e2b9f 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * 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,
                        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:
@@ -606,24 +606,15 @@ ProcessUtility(Node *parsetree,
            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:
index 653e22686f5074caf24d2b0c3b4c76227447c08c..551deae0956d811be8cc1799faeb5660e0ce7242 100644 (file)
@@ -7,7 +7,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -29,7 +29,7 @@ extern void DefineIndex(RangeVar *heapRelation,
            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);
@@ -42,16 +42,15 @@ extern void CreateFunction(CreateFunctionStmt *stmt);
 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 */
index 646ae45d240375025af62bd9bda6e355d9b533dd..d38ea537c6d932c708ffdc38a1d871c3297a1d64 100644 (file)
@@ -7,7 +7,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -34,13 +34,15 @@ extern void AlterTableAlterColumnFlags(Oid myrelid, bool inh,
                                       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);
 
@@ -48,7 +50,7 @@ extern void AlterTableOwner(Oid relationOid, int32 newOwnerSysId);
 
 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);
 
index 4fd6bd9a1a5a93e814986ed21e2276ee76c26dfb..3603f2a4fab260310436cde4be158550763c1799 100644 (file)
@@ -7,7 +7,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,6 +17,6 @@
 #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 */
index c561ac621830c60c59f0717fc740990f7a4c0e98..ce914c5cd0911edd94527e6d9bc8c033a0c0946b 100644 (file)
@@ -7,7 +7,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -737,6 +737,12 @@ typedef struct CreateSchemaStmt
    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
  *
@@ -765,7 +771,7 @@ typedef struct AlterTableStmt
    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;
 
 /* ----------------------
@@ -996,6 +1002,7 @@ typedef struct DropPLangStmt
 {
    NodeTag     type;
    char       *plname;         /* PL name */
+   DropBehavior behavior;      /* RESTRICT or CASCADE behavior */
 } DropPLangStmt;
 
 /* ----------------------
@@ -1107,8 +1114,8 @@ typedef struct DropStmt
 {
    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;
 
 /* ----------------------
@@ -1127,7 +1134,8 @@ typedef struct DropPropertyStmt
    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;
 
 /* ----------------------
@@ -1218,6 +1226,7 @@ typedef struct RemoveAggrStmt
    NodeTag     type;
    List       *aggname;        /* aggregate to drop */
    TypeName   *aggtype;        /* TypeName for input datatype, or NULL */
+   DropBehavior behavior;      /* RESTRICT or CASCADE behavior */
 } RemoveAggrStmt;
 
 /* ----------------------
@@ -1229,6 +1238,7 @@ typedef struct RemoveFuncStmt
    NodeTag     type;
    List       *funcname;       /* function to drop */
    List       *args;           /* types of the arguments */
+   DropBehavior behavior;      /* RESTRICT or CASCADE behavior */
 } RemoveFuncStmt;
 
 /* ----------------------
@@ -1240,6 +1250,7 @@ typedef struct RemoveOperStmt
    NodeTag     type;
    List       *opname;         /* operator to drop */
    List       *args;           /* types of the arguments */
+   DropBehavior behavior;      /* RESTRICT or CASCADE behavior */
 } RemoveOperStmt;
 
 /* ----------------------