Skip to content

Commit 33b4ad6

Browse files
committed
Revert patch, doesn't do what it should:
* %Disallow changing default expression of a SERIAL column Dhanaraj M
1 parent cdd5178 commit 33b4ad6

File tree

7 files changed

+14
-151
lines changed

7 files changed

+14
-151
lines changed

doc/TODO

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ Data Types
208208
The positive modulus result returned by NUMERICs might be considered
209209
inaccurate, in one sense.
210210

211-
* -Disallow changing DEFAULT expression of a SERIAL column
211+
* %Disallow changing DEFAULT expression of a SERIAL column?
212+
213+
This should be done only if the existing SERIAL problems cannot be
214+
fixed.
215+
212216
* %Disallow ALTER SEQUENCE changes for SERIAL sequences because pg_dump
213217
does not dump the changes
214218
* Fix data types where equality comparison isn't intuitive, e.g. box

doc/src/FAQ/TODO.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ <h1><a name="section_4">Data Types</a></h1>
190190
inaccurate, in one sense.
191191
</p>
192192
<ul>
193-
<li>-<em>Disallow changing DEFAULT expression of a SERIAL column</em>
193+
<li>%Disallow changing DEFAULT expression of a SERIAL column?
194+
<p> This should be done only if the existing SERIAL problems cannot be
195+
fixed.
196+
</p>
194197
</li><li>%Disallow ALTER SEQUENCE changes for SERIAL sequences because pg_dump
195198
does not dump the changes
196199
</li><li>Fix data types where equality comparison isn't intuitive, e.g. box

src/backend/catalog/dependency.c

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/dependency.c,v 1.55 2006/06/27 03:21:54 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/dependency.c,v 1.56 2006/06/27 18:35:05 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1927,89 +1927,3 @@ getRelationDescription(StringInfo buffer, Oid relid)
19271927

19281928
ReleaseSysCache(relTup);
19291929
}
1930-
1931-
/* Recursively travel and search for the default sequence. Finally detach it */
1932-
1933-
void performSequenceDefaultDeletion(const ObjectAddress *object,
1934-
DropBehavior behavior, int deleteFlag)
1935-
{
1936-
1937-
ScanKeyData key[3];
1938-
int nkeys;
1939-
SysScanDesc scan;
1940-
HeapTuple tup;
1941-
ObjectAddress otherObject;
1942-
Relation depRel;
1943-
1944-
depRel = heap_open(DependRelationId, RowExclusiveLock);
1945-
1946-
ScanKeyInit(&key[0],
1947-
Anum_pg_depend_classid,
1948-
BTEqualStrategyNumber, F_OIDEQ,
1949-
ObjectIdGetDatum(object->classId));
1950-
ScanKeyInit(&key[1],
1951-
Anum_pg_depend_objid,
1952-
BTEqualStrategyNumber, F_OIDEQ,
1953-
ObjectIdGetDatum(object->objectId));
1954-
if (object->objectSubId != 0)
1955-
{
1956-
ScanKeyInit(&key[2],
1957-
Anum_pg_depend_objsubid,
1958-
BTEqualStrategyNumber, F_INT4EQ,
1959-
Int32GetDatum(object->objectSubId));
1960-
nkeys = 3;
1961-
}
1962-
else
1963-
nkeys = 2;
1964-
1965-
scan = systable_beginscan(depRel, DependDependerIndexId, true,
1966-
SnapshotNow, nkeys, key);
1967-
1968-
while (HeapTupleIsValid(tup = systable_getnext(scan)))
1969-
{
1970-
1971-
Form_pg_depend foundDep = (Form_pg_depend) GETSTRUCT(tup);
1972-
1973-
otherObject.classId = foundDep->refclassid;
1974-
otherObject.objectId = foundDep->refobjid;
1975-
otherObject.objectSubId = foundDep->refobjsubid;
1976-
1977-
/* Detach the default sequence from the relation */
1978-
if(deleteFlag == 1)
1979-
{
1980-
simple_heap_delete(depRel, &tup->t_self);
1981-
break;
1982-
}
1983-
1984-
switch (foundDep->deptype)
1985-
{
1986-
case DEPENDENCY_NORMAL:
1987-
{
1988-
1989-
if(getObjectClass(&otherObject) == OCLASS_CLASS)
1990-
{
1991-
/* Dont allow to change the default sequence */
1992-
if(deleteFlag == 2)
1993-
{
1994-
systable_endscan(scan);
1995-
heap_close(depRel, RowExclusiveLock);
1996-
elog(ERROR, "%s is a SERIAL sequence. Can't alter the relation", getObjectDescription(&otherObject));
1997-
return;
1998-
}
1999-
else /* Detach the default sequence from the relation */
2000-
{
2001-
performSequenceDefaultDeletion(&otherObject, behavior, 1);
2002-
systable_endscan(scan);
2003-
heap_close(depRel, RowExclusiveLock);
2004-
return;
2005-
}
2006-
}
2007-
}
2008-
2009-
}
2010-
}
2011-
2012-
systable_endscan(scan);
2013-
heap_close(depRel, RowExclusiveLock);
2014-
2015-
}

src/backend/catalog/heap.c

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.300 2006/06/27 03:21:54 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.301 2006/06/27 18:35:05 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -2133,50 +2133,3 @@ heap_truncate_find_FKs(List *relationIds)
21332133

21342134
return result;
21352135
}
2136-
2137-
2138-
/* Detach the default sequence and the relation */
2139-
2140-
void
2141-
RemoveSequenceDefault(Oid relid, AttrNumber attnum,
2142-
DropBehavior behavior, bool flag)
2143-
{
2144-
Relation attrdef_rel;
2145-
ScanKeyData scankeys[2];
2146-
SysScanDesc scan;
2147-
HeapTuple tuple;
2148-
2149-
attrdef_rel = heap_open(AttrDefaultRelationId, RowExclusiveLock);
2150-
2151-
ScanKeyInit(&scankeys[0],
2152-
Anum_pg_attrdef_adrelid,
2153-
BTEqualStrategyNumber, F_OIDEQ,
2154-
ObjectIdGetDatum(relid));
2155-
ScanKeyInit(&scankeys[1],
2156-
Anum_pg_attrdef_adnum,
2157-
BTEqualStrategyNumber, F_INT2EQ,
2158-
Int16GetDatum(attnum));
2159-
2160-
scan = systable_beginscan(attrdef_rel, AttrDefaultIndexId, true,
2161-
SnapshotNow, 2, scankeys);
2162-
2163-
/* There should be at most one matching tuple, but we loop anyway */
2164-
while (HeapTupleIsValid(tuple = systable_getnext(scan)))
2165-
{
2166-
ObjectAddress object;
2167-
2168-
object.classId = AttrDefaultRelationId;
2169-
object.objectId = HeapTupleGetOid(tuple);
2170-
object.objectSubId = 0;
2171-
2172-
if(flag == true) /* Detach the sequence */
2173-
performSequenceDefaultDeletion(&object, behavior, 0);
2174-
else /* Don't allow to change the default sequence */
2175-
performSequenceDefaultDeletion(&object, behavior, 2);
2176-
2177-
}
2178-
2179-
systable_endscan(scan);
2180-
heap_close(attrdef_rel, RowExclusiveLock);
2181-
2182-
}

src/backend/commands/tablecmds.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.187 2006/06/27 03:43:19 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.188 2006/06/27 18:35:05 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3404,11 +3404,6 @@ ATExecColumnDefault(Relation rel, const char *colName,
34043404
* safety, but at present we do not expect anything to depend on the
34053405
* default.
34063406
*/
3407-
if (newDefault)
3408-
RemoveSequenceDefault(RelationGetRelid(rel), attnum, DROP_RESTRICT, false);
3409-
else
3410-
RemoveSequenceDefault(RelationGetRelid(rel), attnum, DROP_RESTRICT, true);
3411-
34123407
RemoveAttrDefault(RelationGetRelid(rel), attnum, DROP_RESTRICT, false);
34133408

34143409
if (newDefault)

src/include/catalog/dependency.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/dependency.h,v 1.24 2006/06/27 03:21:55 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/dependency.h,v 1.25 2006/06/27 18:35:05 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -207,7 +207,4 @@ extern void shdepDropOwned(List *relids, DropBehavior behavior);
207207

208208
extern void shdepReassignOwned(List *relids, Oid newrole);
209209

210-
extern void performSequenceDefaultDeletion(const ObjectAddress *object,
211-
DropBehavior behavior, int deleteFlag);
212-
213210
#endif /* DEPENDENCY_H */

src/include/catalog/heap.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/heap.h,v 1.81 2006/06/27 03:21:55 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/heap.h,v 1.82 2006/06/27 18:35:05 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -97,7 +97,4 @@ extern void CheckAttributeNamesTypes(TupleDesc tupdesc, char relkind);
9797

9898
extern void CheckAttributeType(const char *attname, Oid atttypid);
9999

100-
extern void RemoveSequenceDefault(Oid relid, AttrNumber attnum,
101-
DropBehavior behavior, bool flag);
102-
103100
#endif /* HEAP_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy