mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-12 18:34:36 +08:00
Restore ALTER TABLE .. ADD COLUMN w/DEFAULT restriction.
This reverts commit a06e41deeb
of 2011-01-26.
Per discussion, this behavior is not wanted, as it would need to change if
we ever made composite types support DEFAULT.
This commit is contained in:
parent
81c48aeaa8
commit
a40b1e0bf3
@ -142,7 +142,6 @@ typedef struct AlteredTableInfo
|
|||||||
List *newvals; /* List of NewColumnValue */
|
List *newvals; /* List of NewColumnValue */
|
||||||
bool new_notnull; /* T if we added new NOT NULL constraints */
|
bool new_notnull; /* T if we added new NOT NULL constraints */
|
||||||
bool new_changeoids; /* T if we added/dropped the OID column */
|
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 */
|
Oid newTableSpace; /* new tablespace; 0 means no change */
|
||||||
/* Objects to rebuild after completing ALTER TYPE operations */
|
/* Objects to rebuild after completing ALTER TYPE operations */
|
||||||
List *changedConstraintOids; /* OIDs of constraints to rebuild */
|
List *changedConstraintOids; /* OIDs of constraints to rebuild */
|
||||||
@ -3379,14 +3378,14 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we change column data types or add/remove OIDs, the operation has to
|
* If we need to rewrite the table, the operation has to be propagated to
|
||||||
* be propagated to tables that use this table's rowtype as a column type.
|
* tables that use this table's rowtype as a column type.
|
||||||
*
|
*
|
||||||
* (Eventually this will probably become true for scans as well, but at
|
* (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
|
* the moment a composite type does not enforce any constraints, so it's
|
||||||
* not necessary/appropriate to enforce them just during ALTER.)
|
* not necessary/appropriate to enforce them just during ALTER.)
|
||||||
*/
|
*/
|
||||||
if (tab->new_changetypes || tab->new_changeoids)
|
if (newrel)
|
||||||
find_composite_type_dependencies(oldrel->rd_rel->reltype,
|
find_composite_type_dependencies(oldrel->rd_rel->reltype,
|
||||||
RelationGetRelationName(oldrel),
|
RelationGetRelationName(oldrel),
|
||||||
NULL);
|
NULL);
|
||||||
@ -6432,7 +6431,6 @@ ATPrepAlterColumnType(List **wqueue,
|
|||||||
newval->expr = (Expr *) transform;
|
newval->expr = (Expr *) transform;
|
||||||
|
|
||||||
tab->newvals = lappend(tab->newvals, newval);
|
tab->newvals = lappend(tab->newvals, newval);
|
||||||
tab->new_changetypes = true;
|
|
||||||
}
|
}
|
||||||
else if (tab->relkind == RELKIND_FOREIGN_TABLE)
|
else if (tab->relkind == RELKIND_FOREIGN_TABLE)
|
||||||
{
|
{
|
||||||
|
@ -82,14 +82,11 @@ select * from people;
|
|||||||
(Joe,Blow) | 01-10-1984
|
(Joe,Blow) | 01-10-1984
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- the default doesn't need to propagate through to the rowtypes, so this is OK
|
-- at the moment this will not work due to ALTER TABLE inadequacy:
|
||||||
alter table fullname add column suffix text default '';
|
alter table fullname add column suffix text default '';
|
||||||
alter table fullname drop column suffix;
|
|
||||||
-- this one, without a default, is OK too
|
|
||||||
alter table fullname add column suffix text default null;
|
|
||||||
-- but this should fail, due to ALTER TABLE inadequacy
|
|
||||||
alter table fullname alter column suffix set data type integer using null;
|
|
||||||
ERROR: cannot alter table "fullname" because column "people"."fn" uses its rowtype
|
ERROR: cannot alter table "fullname" because column "people"."fn" uses its rowtype
|
||||||
|
-- but this should work:
|
||||||
|
alter table fullname add column suffix text default null;
|
||||||
select * from people;
|
select * from people;
|
||||||
fn | bd
|
fn | bd
|
||||||
-------------+------------
|
-------------+------------
|
||||||
|
@ -45,16 +45,12 @@ insert into people values ('(Joe,Blow)', '1984-01-10');
|
|||||||
|
|
||||||
select * from people;
|
select * from people;
|
||||||
|
|
||||||
-- the default doesn't need to propagate through to the rowtypes, so this is OK
|
-- at the moment this will not work due to ALTER TABLE inadequacy:
|
||||||
alter table fullname add column suffix text default '';
|
alter table fullname add column suffix text default '';
|
||||||
alter table fullname drop column suffix;
|
|
||||||
|
|
||||||
-- this one, without a default, is OK too
|
-- but this should work:
|
||||||
alter table fullname add column suffix text default null;
|
alter table fullname add column suffix text default null;
|
||||||
|
|
||||||
-- but this should fail, due to ALTER TABLE inadequacy
|
|
||||||
alter table fullname alter column suffix set data type integer using null;
|
|
||||||
|
|
||||||
select * from people;
|
select * from people;
|
||||||
|
|
||||||
-- test insertion/updating of subfields
|
-- test insertion/updating of subfields
|
||||||
|
Loading…
Reference in New Issue
Block a user