mirror of
https://github.com/postgres/postgres.git
synced 2025-08-25 20:23:07 +03:00
DROP ... IF EXISTS for the following cases:
language, tablespace, trigger, rule, opclass, function, aggregate. operator, and cast.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.34 2006/04/15 17:45:33 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.35 2006/06/16 20:23:44 adunstan Exp $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The "DefineFoo" routines take the parse tree and pick out the
|
||||
@@ -211,7 +211,21 @@ RemoveAggregate(RemoveFuncStmt *stmt)
|
||||
ObjectAddress object;
|
||||
|
||||
/* Look up function and make sure it's an aggregate */
|
||||
procOid = LookupAggNameTypeNames(aggName, aggArgs, false);
|
||||
procOid = LookupAggNameTypeNames(aggName, aggArgs, stmt->missing_ok);
|
||||
|
||||
if (!OidIsValid(procOid))
|
||||
{
|
||||
/* we only get here if stmt->missing_ok is true */
|
||||
|
||||
/* XXX might need better message here */
|
||||
|
||||
ereport(NOTICE,
|
||||
(errmsg("aggregate %s does not exist ... skipping",
|
||||
stmt->name)));
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the function tuple, do permissions and validity checks
|
||||
|
@@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.74 2006/04/15 17:45:34 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.75 2006/06/16 20:23:44 adunstan Exp $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* These routines take the parse tree and pick out the
|
||||
@@ -687,7 +687,16 @@ RemoveFunction(RemoveFuncStmt *stmt)
|
||||
/*
|
||||
* Find the function, do permissions and validity checks
|
||||
*/
|
||||
funcOid = LookupFuncNameTypeNames(functionName, argTypes, false);
|
||||
funcOid = LookupFuncNameTypeNames(functionName, argTypes, stmt->missing_ok);
|
||||
if (stmt->missing_ok &&!OidIsValid(funcOid))
|
||||
{
|
||||
ereport(NOTICE,
|
||||
(errmsg("function %s(%s) does not exist ... skipping",
|
||||
NameListToString(functionName),
|
||||
NameListToString(argTypes))));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
tup = SearchSysCache(PROCOID,
|
||||
ObjectIdGetDatum(funcOid),
|
||||
@@ -1377,6 +1386,7 @@ DropCast(DropCastStmt *stmt)
|
||||
HeapTuple tuple;
|
||||
ObjectAddress object;
|
||||
|
||||
/* when dropping a cast, the types must exist even if you use IF EXISTS */
|
||||
sourcetypeid = typenameTypeId(NULL, stmt->sourcetype);
|
||||
targettypeid = typenameTypeId(NULL, stmt->targettype);
|
||||
|
||||
@@ -1385,11 +1395,23 @@ DropCast(DropCastStmt *stmt)
|
||||
ObjectIdGetDatum(targettypeid),
|
||||
0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("cast from type %s to type %s does not exist",
|
||||
TypeNameToString(stmt->sourcetype),
|
||||
TypeNameToString(stmt->targettype))));
|
||||
{
|
||||
if (! stmt->missing_ok)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("cast from type %s to type %s does not exist",
|
||||
TypeNameToString(stmt->sourcetype),
|
||||
TypeNameToString(stmt->targettype))));
|
||||
else
|
||||
ereport(NOTICE,
|
||||
(errmsg("cast from type %s to type %s does not exist ... skipping",
|
||||
TypeNameToString(stmt->sourcetype),
|
||||
TypeNameToString(stmt->targettype))));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Permission check */
|
||||
if (!pg_type_ownercheck(sourcetypeid, GetUserId())
|
||||
|
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.45 2006/05/02 22:25:10 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.46 2006/06/16 20:23:44 adunstan Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -700,21 +700,40 @@ RemoveOpClass(RemoveOpClassStmt *stmt)
|
||||
/* Unqualified opclass name, so search the search path */
|
||||
opcID = OpclassnameGetOpcid(amID, opcname);
|
||||
if (!OidIsValid(opcID))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("operator class \"%s\" does not exist for access method \"%s\"",
|
||||
opcname, stmt->amname)));
|
||||
{
|
||||
if (! stmt -> missing_ok )
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("operator class \"%s\" does not exist for access method \"%s\"",
|
||||
opcname, stmt->amname)));
|
||||
else
|
||||
ereport(NOTICE,
|
||||
(errmsg("operator class \"%s\" does not exist for access method \"%s\"",
|
||||
opcname, stmt->amname)));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
tuple = SearchSysCache(CLAOID,
|
||||
ObjectIdGetDatum(opcID),
|
||||
0, 0, 0);
|
||||
}
|
||||
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("operator class \"%s\" does not exist for access method \"%s\"",
|
||||
NameListToString(stmt->opclassname), stmt->amname)));
|
||||
|
||||
{
|
||||
|
||||
if (! stmt->missing_ok )
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("operator class \"%s\" does not exist for access method \"%s\"",
|
||||
NameListToString(stmt->opclassname), stmt->amname)));
|
||||
else
|
||||
ereport(NOTICE,
|
||||
(errmsg("operator class \"%s\" does not exist for access method \"%s\"",
|
||||
NameListToString(stmt->opclassname), stmt->amname)));
|
||||
return;
|
||||
}
|
||||
|
||||
opcID = HeapTupleGetOid(tuple);
|
||||
|
||||
/* Permission check: must own opclass or its namespace */
|
||||
|
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/operatorcmds.c,v 1.30 2006/04/15 17:45:34 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/operatorcmds.c,v 1.31 2006/06/16 20:23:44 adunstan Exp $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The "DefineFoo" routines take the parse tree and pick out the
|
||||
@@ -213,7 +213,15 @@ RemoveOperator(RemoveFuncStmt *stmt)
|
||||
Assert(list_length(stmt->args) == 2);
|
||||
operOid = LookupOperNameTypeNames(NULL, operatorName,
|
||||
typeName1, typeName2,
|
||||
false, -1);
|
||||
stmt->missing_ok, -1);
|
||||
|
||||
if (stmt->missing_ok &&!OidIsValid(operOid) )
|
||||
{
|
||||
ereport(NOTICE,
|
||||
(errmsg("operator %s does not exist ... skipping",
|
||||
NameListToString(operatorName))));
|
||||
return;
|
||||
}
|
||||
|
||||
tup = SearchSysCache(OPEROID,
|
||||
ObjectIdGetDatum(operOid),
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/proclang.c,v 1.64 2006/03/05 15:58:24 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/proclang.c,v 1.65 2006/06/16 20:23:44 adunstan Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -396,9 +396,18 @@ DropProceduralLanguage(DropPLangStmt *stmt)
|
||||
CStringGetDatum(languageName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(langTup))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("language \"%s\" does not exist", languageName)));
|
||||
{
|
||||
if (! stmt->missing_ok)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("language \"%s\" does not exist", languageName)));
|
||||
else
|
||||
ereport(NOTICE,
|
||||
(errmsg("language \"%s\" does not exist ... skipping",
|
||||
languageName)));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
object.classId = LanguageRelationId;
|
||||
object.objectId = HeapTupleGetOid(langTup);
|
||||
|
@@ -37,7 +37,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.34 2006/03/29 21:17:38 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.35 2006/06/16 20:23:44 adunstan Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -403,10 +403,25 @@ DropTableSpace(DropTableSpaceStmt *stmt)
|
||||
tuple = heap_getnext(scandesc, ForwardScanDirection);
|
||||
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("tablespace \"%s\" does not exist",
|
||||
tablespacename)));
|
||||
{
|
||||
if ( ! stmt->missing_ok )
|
||||
{
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("tablespace \"%s\" does not exist",
|
||||
tablespacename)));
|
||||
}
|
||||
else
|
||||
{
|
||||
ereport(NOTICE,
|
||||
(errmsg("tablespace \"%s\" does not exist ... skipping",
|
||||
tablespacename)));
|
||||
/* XXX I assume I need one or both of these next two calls */
|
||||
heap_endscan(scandesc);
|
||||
heap_close(rel, NoLock);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
tablespaceoid = HeapTupleGetOid(tuple);
|
||||
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.202 2006/05/30 14:01:57 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.203 2006/06/16 20:23:44 adunstan Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -452,7 +452,8 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
|
||||
* DropTrigger - drop an individual trigger by name
|
||||
*/
|
||||
void
|
||||
DropTrigger(Oid relid, const char *trigname, DropBehavior behavior)
|
||||
DropTrigger(Oid relid, const char *trigname, DropBehavior behavior,
|
||||
bool missing_ok)
|
||||
{
|
||||
Relation tgrel;
|
||||
ScanKeyData skey[2];
|
||||
@@ -481,10 +482,21 @@ DropTrigger(Oid relid, const char *trigname, DropBehavior behavior)
|
||||
tup = systable_getnext(tgscan);
|
||||
|
||||
if (!HeapTupleIsValid(tup))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("trigger \"%s\" for table \"%s\" does not exist",
|
||||
trigname, get_rel_name(relid))));
|
||||
{
|
||||
if (! missing_ok)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("trigger \"%s\" for table \"%s\" does not exist",
|
||||
trigname, get_rel_name(relid))));
|
||||
else
|
||||
ereport(NOTICE,
|
||||
(errmsg("trigger \"%s\" for table \"%s\" does not exist ...skipping",
|
||||
trigname, get_rel_name(relid))));
|
||||
/* cleanup */
|
||||
systable_endscan(tgscan);
|
||||
heap_close(tgrel, AccessShareLock);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pg_class_ownercheck(relid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
|
||||
|
Reference in New Issue
Block a user