Skip to content

Commit a40b1e0

Browse files
committed
Restore ALTER TABLE .. ADD COLUMN w/DEFAULT restriction.
This reverts commit a06e41d 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.
1 parent 81c48ae commit a40b1e0

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

src/backend/commands/tablecmds.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ typedef struct AlteredTableInfo
142142
List *newvals; /* List of NewColumnValue */
143143
bool new_notnull; /* T if we added new NOT NULL constraints */
144144
bool new_changeoids; /* T if we added/dropped the OID column */
145-
bool new_changetypes; /* T if we changed column types */
146145
Oid newTableSpace; /* new tablespace; 0 means no change */
147146
/* Objects to rebuild after completing ALTER TYPE operations */
148147
List *changedConstraintOids; /* OIDs of constraints to rebuild */
@@ -3379,14 +3378,14 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
33793378
}
33803379

33813380
/*
3382-
* If we change column data types or add/remove OIDs, the operation has to
3383-
* be propagated to tables that use this table's rowtype as a column type.
3381+
* If we need to rewrite the table, the operation has to be propagated to
3382+
* tables that use this table's rowtype as a column type.
33843383
*
33853384
* (Eventually this will probably become true for scans as well, but at
33863385
* the moment a composite type does not enforce any constraints, so it's
33873386
* not necessary/appropriate to enforce them just during ALTER.)
33883387
*/
3389-
if (tab->new_changetypes || tab->new_changeoids)
3388+
if (newrel)
33903389
find_composite_type_dependencies(oldrel->rd_rel->reltype,
33913390
RelationGetRelationName(oldrel),
33923391
NULL);
@@ -6432,7 +6431,6 @@ ATPrepAlterColumnType(List **wqueue,
64326431
newval->expr = (Expr *) transform;
64336432

64346433
tab->newvals = lappend(tab->newvals, newval);
6435-
tab->new_changetypes = true;
64366434
}
64376435
else if (tab->relkind == RELKIND_FOREIGN_TABLE)
64386436
{

src/test/regress/expected/rowtypes.out

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,11 @@ select * from people;
8282
(Joe,Blow) | 01-10-1984
8383
(1 row)
8484

85-
-- the default doesn't need to propagate through to the rowtypes, so this is OK
85+
-- at the moment this will not work due to ALTER TABLE inadequacy:
8686
alter table fullname add column suffix text default '';
87-
alter table fullname drop column suffix;
88-
-- this one, without a default, is OK too
89-
alter table fullname add column suffix text default null;
90-
-- but this should fail, due to ALTER TABLE inadequacy
91-
alter table fullname alter column suffix set data type integer using null;
9287
ERROR: cannot alter table "fullname" because column "people"."fn" uses its rowtype
88+
-- but this should work:
89+
alter table fullname add column suffix text default null;
9390
select * from people;
9491
fn | bd
9592
-------------+------------

src/test/regress/sql/rowtypes.sql

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,12 @@ insert into people values ('(Joe,Blow)', '1984-01-10');
4545

4646
select * from people;
4747

48-
-- the default doesn't need to propagate through to the rowtypes, so this is OK
48+
-- at the moment this will not work due to ALTER TABLE inadequacy:
4949
alter table fullname add column suffix text default '';
50-
alter table fullname drop column suffix;
5150

52-
-- this one, without a default, is OK too
51+
-- but this should work:
5352
alter table fullname add column suffix text default null;
5453

55-
-- but this should fail, due to ALTER TABLE inadequacy
56-
alter table fullname alter column suffix set data type integer using null;
57-
5854
select * from people;
5955

6056
-- test insertion/updating of subfields

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