Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita40b1e0

Browse files
committed
Restore ALTER TABLE .. ADD COLUMN w/DEFAULT restriction.
This reverts commita06e41d of 2011-01-26.Per discussion, this behavior is not wanted, as it would need to change ifwe ever made composite types support DEFAULT.
1 parent81c48ae commita40b1e0

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
boolnew_notnull;/* T if we added new NOT NULL constraints */
144144
boolnew_changeoids;/* T if we added/dropped the OID column */
145-
boolnew_changetypes;/* T if we changed column types */
146145
OidnewTableSpace;/* 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 wechange column data types or add/remove OIDs, the operation has to
3383-
*be propagated totables that use this table's rowtype as a column type.
3381+
* If weneed 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
elseif (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-
-- thedefault doesn't need to propagate through tothe rowtypes, so this is OK
85+
--atthemoment this will not work due toALTER 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-
-- thedefault doesn't need to propagate through tothe rowtypes, so this is OK
48+
--atthemoment this will not work due toALTER TABLE inadequacy:
4949
altertable fullname add column suffixtext default'';
50-
altertable fullname drop column suffix;
5150

52-
-- thisone, without a default, is OK too
51+
--butthisshould work:
5352
altertable fullname add column suffixtext defaultnull;
5453

55-
-- but this should fail, due to ALTER TABLE inadequacy
56-
altertable fullname alter column suffixset data typeinteger usingnull;
57-
5854
select*from people;
5955

6056
-- test insertion/updating of subfields

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp