1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

Standardize get_whatever_oid functions for other object types.

- Rename TSParserGetPrsid to get_ts_parser_oid.
- Rename TSDictionaryGetDictid to get_ts_dict_oid.
- Rename TSTemplateGetTmplid to get_ts_template_oid.
- Rename TSConfigGetCfgid to get_ts_config_oid.
- Rename FindConversionByName to get_conversion_oid.
- Rename GetConstraintName to get_constraint_oid.
- Add new functions get_opclass_oid, get_opfamily_oid, get_rewrite_oid,
  get_rewrite_oid_without_relid, get_trigger_oid, and get_cast_oid.

The name of each function matches the corresponding catalog.

Thanks to KaiGai Kohei for the review.
This commit is contained in:
Robert Haas
2010-08-05 15:25:36 +00:00
parent 2a6ef3445c
commit fd1843ff89
22 changed files with 401 additions and 504 deletions

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.263 2010/07/28 05:22:24 sriggs Exp $
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.264 2010/08/05 15:25:35 rhaas Exp $
*
*-------------------------------------------------------------------------
*/
@ -967,46 +967,17 @@ void
DropTrigger(Oid relid, const char *trigname, DropBehavior behavior,
bool missing_ok)
{
Relation tgrel;
ScanKeyData skey[2];
SysScanDesc tgscan;
HeapTuple tup;
ObjectAddress object;
/*
* Find the trigger, verify permissions, set up object address
*/
tgrel = heap_open(TriggerRelationId, AccessShareLock);
object.classId = TriggerRelationId;
object.objectId = get_trigger_oid(relid, trigname, missing_ok);
object.objectSubId = 0;
ScanKeyInit(&skey[0],
Anum_pg_trigger_tgrelid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(relid));
ScanKeyInit(&skey[1],
Anum_pg_trigger_tgname,
BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum(trigname));
tgscan = systable_beginscan(tgrel, TriggerRelidNameIndexId, true,
SnapshotNow, 2, skey);
tup = systable_getnext(tgscan);
if (!HeapTupleIsValid(tup))
if (!OidIsValid(object.objectId))
{
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);
ereport(NOTICE,
(errmsg("trigger \"%s\" for table \"%s\" does not exist, skipping",
trigname, get_rel_name(relid))));
return;
}
@ -1014,13 +985,6 @@ DropTrigger(Oid relid, const char *trigname, DropBehavior behavior,
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
get_rel_name(relid));
object.classId = TriggerRelationId;
object.objectId = HeapTupleGetOid(tup);
object.objectSubId = 0;
systable_endscan(tgscan);
heap_close(tgrel, AccessShareLock);
/*
* Do the deletion
*/
@ -1102,6 +1066,59 @@ RemoveTriggerById(Oid trigOid)
heap_close(rel, NoLock);
}
/*
* get_trigger_oid - Look up a trigger by name to find its OID.
*
* If missing_ok is false, throw an error if trigger not found. If
* true, just return InvalidOid.
*/
Oid
get_trigger_oid(Oid relid, const char *trigname, bool missing_ok)
{
Relation tgrel;
ScanKeyData skey[2];
SysScanDesc tgscan;
HeapTuple tup;
Oid oid;
/*
* Find the trigger, verify permissions, set up object address
*/
tgrel = heap_open(TriggerRelationId, AccessShareLock);
ScanKeyInit(&skey[0],
Anum_pg_trigger_tgrelid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(relid));
ScanKeyInit(&skey[1],
Anum_pg_trigger_tgname,
BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum(trigname));
tgscan = systable_beginscan(tgrel, TriggerRelidNameIndexId, true,
SnapshotNow, 2, skey);
tup = systable_getnext(tgscan);
if (!HeapTupleIsValid(tup))
{
if (!missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("trigger \"%s\" for table \"%s\" does not exist",
trigname, get_rel_name(relid))));
oid = InvalidOid;
}
else
{
oid = HeapTupleGetOid(tup);
}
systable_endscan(tgscan);
heap_close(tgrel, AccessShareLock);
return oid;
}
/*
* renametrig - changes the name of a trigger on a relation
*