mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
Remove arbitrary ALTER TABLE .. ADD COLUMN restriction.
The previous coding prevented ALTER TABLE .. ADD COLUMN from being used with a non-NULL default in situations where the table's rowtype was being used elsewhere. But this is a completely arbitrary restriction since you could do the same operation in multiple steps (add the column, add the default, update the table). Inspired by a patch from Noah Misch, though I didn't use his code.
This commit is contained in:
@ -142,6 +142,7 @@ typedef struct AlteredTableInfo
|
||||
List *newvals; /* List of NewColumnValue */
|
||||
bool new_notnull; /* T if we added new NOT NULL constraints */
|
||||
bool new_changeoids; /* T if we added/dropped the OID column */
|
||||
bool new_changetypes; /* T if we changed column types */
|
||||
Oid newTableSpace; /* new tablespace; 0 means no change */
|
||||
/* Objects to rebuild after completing ALTER TYPE operations */
|
||||
List *changedConstraintOids; /* OIDs of constraints to rebuild */
|
||||
@ -3378,14 +3379,14 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
|
||||
}
|
||||
|
||||
/*
|
||||
* If we need to rewrite the table, the operation has to be propagated to
|
||||
* tables that use this table's rowtype as a column type.
|
||||
* If we change column data types or add/remove OIDs, the operation has to
|
||||
* be propagated to tables that use this table's rowtype as a column type.
|
||||
*
|
||||
* (Eventually this will probably become true for scans as well, but at
|
||||
* the moment a composite type does not enforce any constraints, so it's
|
||||
* not necessary/appropriate to enforce them just during ALTER.)
|
||||
*/
|
||||
if (newrel)
|
||||
if (tab->new_changetypes || tab->new_changeoids)
|
||||
find_composite_type_dependencies(oldrel->rd_rel->reltype,
|
||||
RelationGetRelationName(oldrel),
|
||||
NULL);
|
||||
@ -6429,6 +6430,7 @@ ATPrepAlterColumnType(List **wqueue,
|
||||
newval->expr = (Expr *) transform;
|
||||
|
||||
tab->newvals = lappend(tab->newvals, newval);
|
||||
tab->new_changetypes = true;
|
||||
}
|
||||
else if (tab->relkind == RELKIND_FOREIGN_TABLE)
|
||||
{
|
||||
|
Reference in New Issue
Block a user