1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Add a missing_ok argument to get_object_address().

This lays the groundwork for an upcoming patch to streamline the
handling of DROP commands.

KaiGai Kohei
This commit is contained in:
Robert Haas
2011-06-27 21:17:25 -04:00
parent e1cd66f748
commit c533c1477f
7 changed files with 178 additions and 79 deletions

View File

@ -132,7 +132,8 @@ get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
* were unique across the entire database.
*/
Oid
get_rewrite_oid_without_relid(const char *rulename, Oid *reloid)
get_rewrite_oid_without_relid(const char *rulename,
Oid *reloid, bool missing_ok)
{
Relation RewriteRelation;
HeapScanDesc scanDesc;
@ -151,20 +152,26 @@ get_rewrite_oid_without_relid(const char *rulename, Oid *reloid)
htup = heap_getnext(scanDesc, ForwardScanDirection);
if (!HeapTupleIsValid(htup))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("rule \"%s\" does not exist", rulename)));
ruleoid = HeapTupleGetOid(htup);
if (reloid != NULL)
*reloid = ((Form_pg_rewrite) GETSTRUCT(htup))->ev_class;
if (HeapTupleIsValid(htup = heap_getnext(scanDesc, ForwardScanDirection)))
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("there are multiple rules named \"%s\"", rulename),
errhint("Specify a relation name as well as a rule name.")));
{
if (!missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("rule \"%s\" does not exist", rulename)));
ruleoid = InvalidOid;
}
else
{
ruleoid = HeapTupleGetOid(htup);
if (reloid != NULL)
*reloid = ((Form_pg_rewrite) GETSTRUCT(htup))->ev_class;
htup = heap_getnext(scanDesc, ForwardScanDirection);
if (HeapTupleIsValid(htup))
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("there are multiple rules named \"%s\"", rulename),
errhint("Specify a relation name as well as a rule name.")));
}
heap_endscan(scanDesc);
heap_close(RewriteRelation, AccessShareLock);