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:
@@ -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);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user