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

Disallow changing/dropping default expression of a SERIAL column

Dhanaraj M
This commit is contained in:
Bruce Momjian
2006-06-27 03:21:55 +00:00
parent ba4b9c0d8c
commit 424b8e64c7
5 changed files with 149 additions and 5 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.299 2006/05/10 23:18:39 tgl Exp $
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.300 2006/06/27 03:21:54 momjian Exp $
*
*
* INTERFACE ROUTINES
@@ -2133,3 +2133,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);
}