mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Unify drop-by-OID functions
There are a number of Remove${Something}ById() functions that are essentially identical in structure and only different in which catalog they are working on. Refactor this to be one generic function. The information about which oid column, index, etc. to use was already available in ObjectProperty for most catalogs, in a few cases it was easily added. Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com> Reviewed-by: Robert Haas <robertmhaas@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/331d9661-1743-857f-1cbb-d5728bcd62cb%402ndquadrant.com
This commit is contained in:
@ -1646,32 +1646,6 @@ CreateCast(CreateCastStmt *stmt)
|
||||
return myself;
|
||||
}
|
||||
|
||||
void
|
||||
DropCastById(Oid castOid)
|
||||
{
|
||||
Relation relation;
|
||||
ScanKeyData scankey;
|
||||
SysScanDesc scan;
|
||||
HeapTuple tuple;
|
||||
|
||||
relation = table_open(CastRelationId, RowExclusiveLock);
|
||||
|
||||
ScanKeyInit(&scankey,
|
||||
Anum_pg_cast_oid,
|
||||
BTEqualStrategyNumber, F_OIDEQ,
|
||||
ObjectIdGetDatum(castOid));
|
||||
scan = systable_beginscan(relation, CastOidIndexId, true,
|
||||
NULL, 1, &scankey);
|
||||
|
||||
tuple = systable_getnext(scan);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "could not find tuple for cast %u", castOid);
|
||||
CatalogTupleDelete(relation, &tuple->t_self);
|
||||
|
||||
systable_endscan(scan);
|
||||
table_close(relation, RowExclusiveLock);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
check_transform_function(Form_pg_proc procstruct)
|
||||
@ -1933,33 +1907,6 @@ get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DropTransformById(Oid transformOid)
|
||||
{
|
||||
Relation relation;
|
||||
ScanKeyData scankey;
|
||||
SysScanDesc scan;
|
||||
HeapTuple tuple;
|
||||
|
||||
relation = table_open(TransformRelationId, RowExclusiveLock);
|
||||
|
||||
ScanKeyInit(&scankey,
|
||||
Anum_pg_transform_oid,
|
||||
BTEqualStrategyNumber, F_OIDEQ,
|
||||
ObjectIdGetDatum(transformOid));
|
||||
scan = systable_beginscan(relation, TransformOidIndexId, true,
|
||||
NULL, 1, &scankey);
|
||||
|
||||
tuple = systable_getnext(scan);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "could not find tuple for transform %u", transformOid);
|
||||
CatalogTupleDelete(relation, &tuple->t_self);
|
||||
|
||||
systable_endscan(scan);
|
||||
table_close(relation, RowExclusiveLock);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Subroutine for ALTER FUNCTION/AGGREGATE SET SCHEMA/RENAME
|
||||
*
|
||||
|
Reference in New Issue
Block a user