diff options
Diffstat (limited to 'src/backend/catalog/heap.c')
-rw-r--r-- | src/backend/catalog/heap.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 962a382b79d..9803720a83e 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.296 2006/04/24 01:40:48 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.297 2006/04/29 16:43:54 momjian Exp $ * * * INTERFACE ROUTINES @@ -2136,3 +2136,50 @@ heap_truncate_find_FKs(List *relationIds) return result; } + + +/* Detach the default sequence and the relation */ + +void +RemoveSequenceDefault(Oid relid, AttrNumber attnum, + DropBehavior behavior, bool flag) +{ + Relation attrdef_rel; + ScanKeyData scankeys[2]; + SysScanDesc scan; + HeapTuple tuple; + + attrdef_rel = heap_open(AttrDefaultRelationId, RowExclusiveLock); + + ScanKeyInit(&scankeys[0], + Anum_pg_attrdef_adrelid, + BTEqualStrategyNumber, F_OIDEQ, + ObjectIdGetDatum(relid)); + ScanKeyInit(&scankeys[1], + Anum_pg_attrdef_adnum, + BTEqualStrategyNumber, F_INT2EQ, + Int16GetDatum(attnum)); + + scan = systable_beginscan(attrdef_rel, AttrDefaultIndexId, true, + SnapshotNow, 2, scankeys); + + /* There should be at most one matching tuple, but we loop anyway */ + while (HeapTupleIsValid(tuple = systable_getnext(scan))) + { + ObjectAddress object; + + object.classId = AttrDefaultRelationId; + object.objectId = HeapTupleGetOid(tuple); + object.objectSubId = 0; + + if(flag == true) /* Detach the sequence */ + performSequenceDefaultDeletion(&object, behavior, 0); + else /* Don't allow to change the default sequence */ + performSequenceDefaultDeletion(&object, behavior, 2); + + } + + systable_endscan(scan); + heap_close(attrdef_rel, RowExclusiveLock); + +} |