Here is an updated patch for the remaining cases of DROP objtype IF
EXISTS ... as recently discussed on -hackers.
The cases are:
language, tablespace, trigger, rule, opclass, function, aggregate.
operator, and cast.
Regression tests and docs still to come.
I wasn't quite sure how to format the message in the case of aggregate -
the change in calls there seems to have made it somewhat harder, so some
advice would be appreciated.
cheers
andrew
Index: src/backend/commands/aggregatecmds.c
===
RCS file: /cvsroot/pgsql/src/backend/commands/aggregatecmds.c,v
retrieving revision 1.34
diff -c -r1.34 aggregatecmds.c
*** src/backend/commands/aggregatecmds.c 15 Apr 2006 17:45:33 - 1.34
--- src/backend/commands/aggregatecmds.c 10 Jun 2006 14:04:54 -
***
*** 211,217
ObjectAddress object;
/* Look up function and make sure it's an aggregate */
! procOid = LookupAggNameTypeNames(aggName, aggArgs, false);
/*
* Find the function tuple, do permissions and validity checks
--- 211,231
ObjectAddress object;
/* Look up function and make sure it's an aggregate */
! 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
Index: src/backend/commands/functioncmds.c
===
RCS file: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v
retrieving revision 1.74
diff -c -r1.74 functioncmds.c
*** src/backend/commands/functioncmds.c 15 Apr 2006 17:45:34 - 1.74
--- src/backend/commands/functioncmds.c 10 Jun 2006 14:04:56 -
***
*** 687,693
/*
* Find the function, do permissions and validity checks
*/
! funcOid = LookupFuncNameTypeNames(functionName, argTypes, false);
tup = SearchSysCache(PROCOID,
ObjectIdGetDatum(funcOid),
--- 687,702
/*
* Find the function, do permissions and validity checks
*/
! 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,1382
--- 1386,1392
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,1395
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;
/* Permission check */
if (!pg_type_ownercheck(sourcetypeid, GetUserId())
--- 1395,1417
ObjectIdGetDatum(targettypeid),
0, 0);
if (!HeapTupleIsValid(tuple))
! {
! 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())
Index: src/backend/commands/opclasscmds.c
===
RCS file: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v
retrieving revision 1.45
diff -c -r1.45 opclasscmds.c
*** src/backend/commands/opclasscmds.c 2 May 2006 22:25:10 - 1.45
--- src/backend/commands/opclasscmds.c 10 Jun 2006 14:04:56 -
***
*** 700,720
/* 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)));
tuple = SearchSysCache(CLAOID,
ObjectIdGetDatum(opcID),
0, 0, 0);
}
if (!HeapTupleIsValid(tuple))
! ereport(ERROR,
! (errcode(ERRCODE_UND