Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6121aed

Browse files
committed
Fix oversight in recent ALTER TABLE improvements. We now support
ALTER TABLE tab ADD COLUMN col SERIAL, but we forgot to install the dependency between the column and the sequence, so the sequence would not go away if you dropped the table later.
1 parent c9d327b commit 6121aed

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

src/backend/commands/tablecmds.c

+26-15
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.113 2004/06/10 17:55:56 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.114 2004/06/10 18:25:02 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -199,6 +199,8 @@ static void ATPrepAddColumn(List **wqueue, Relation rel, bool recurse,
199199
static void ATExecAddColumn(AlteredTableInfo *tab, Relation rel,
200200
ColumnDef *colDef);
201201
static void add_column_datatype_dependency(Oid relid, int32 attnum, Oid typid);
202+
static void add_column_support_dependency(Oid relid, int32 attnum,
203+
RangeVar *support);
202204
static void ATExecDropNotNull(Relation rel, const char *colName);
203205
static void ATExecSetNotNull(AlteredTableInfo *tab, Relation rel,
204206
const char *colName);
@@ -438,20 +440,9 @@ DefineRelation(CreateStmt *stmt, char relkind)
438440
rawDefaults = lappend(rawDefaults, rawEnt);
439441
}
440442

443+
/* Create dependency for supporting relation for this column */
441444
if (colDef->support != NULL)
442-
{
443-
/* Create dependency for supporting relation for this column */
444-
ObjectAddress colobject,
445-
suppobject;
446-
447-
colobject.classId = RelOid_pg_class;
448-
colobject.objectId = relationId;
449-
colobject.objectSubId = attnum;
450-
suppobject.classId = RelOid_pg_class;
451-
suppobject.objectId = RangeVarGetRelid(colDef->support, false);
452-
suppobject.objectSubId = 0;
453-
recordDependencyOn(&suppobject, &colobject, DEPENDENCY_INTERNAL);
454-
}
445+
add_column_support_dependency(relationId, attnum, colDef->support);
455446
}
456447

457448
/*
@@ -2926,9 +2917,11 @@ ATExecAddColumn(AlteredTableInfo *tab, Relation rel,
29262917
}
29272918

29282919
/*
2929-
* Add datatype dependency for the new column.
2920+
* Add needed dependency entries for the new column.
29302921
*/
29312922
add_column_datatype_dependency(myrelid, i, attribute->atttypid);
2923+
if (colDef->support != NULL)
2924+
add_column_support_dependency(myrelid, i, colDef->support);
29322925
}
29332926

29342927
/*
@@ -2949,6 +2942,24 @@ add_column_datatype_dependency(Oid relid, int32 attnum, Oid typid)
29492942
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
29502943
}
29512944

2945+
/*
2946+
* Install a dependency for a column's supporting relation (serial sequence).
2947+
*/
2948+
static void
2949+
add_column_support_dependency(Oid relid, int32 attnum, RangeVar *support)
2950+
{
2951+
ObjectAddress colobject,
2952+
suppobject;
2953+
2954+
colobject.classId = RelOid_pg_class;
2955+
colobject.objectId = relid;
2956+
colobject.objectSubId = attnum;
2957+
suppobject.classId = RelOid_pg_class;
2958+
suppobject.objectId = RangeVarGetRelid(support, false);
2959+
suppobject.objectSubId = 0;
2960+
recordDependencyOn(&suppobject, &colobject, DEPENDENCY_INTERNAL);
2961+
}
2962+
29522963
/*
29532964
* ALTER TABLE ALTER COLUMN DROP NOT NULL
29542965
*/

0 commit comments

Comments
 (0)