From 39b5e5f3370258cae843e8cc83eccd59ddb532dd Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Thu, 20 Jan 2011 22:44:10 -0500 Subject: Make ALTER TABLE revalidate uniqueness and exclusion constraints. Failure to do so can lead to constraint violations. This was broken by commit 1ddc2703a936d03953657f43345460b9242bbed1 on 2010-02-07, so back-patch to 9.0. Noah Misch. Regression test by me. --- src/test/regress/expected/alter_table.out | 4 ++++ src/test/regress/sql/alter_table.sql | 2 ++ 2 files changed, 6 insertions(+) (limited to 'src/test') diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out index 5aff44f23aa..40a907d869e 100644 --- a/src/test/regress/expected/alter_table.out +++ b/src/test/regress/expected/alter_table.out @@ -413,6 +413,10 @@ insert into atacc1 (test) values (4); -- try adding a unique oid constraint alter table atacc1 add constraint atacc_oid1 unique(oid); NOTICE: ALTER TABLE / ADD UNIQUE will create implicit index "atacc_oid1" for table "atacc1" +-- try to create duplicates via alter table using - should fail +alter table atacc1 alter column test type integer using 0; +ERROR: could not create unique index "atacc_test1" +DETAIL: Key (test)=(0) is duplicated. drop table atacc1; -- let's do one where the unique constraint fails when added create table atacc1 ( test int ); diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql index 82c2e4ee017..2b01238e282 100644 --- a/src/test/regress/sql/alter_table.sql +++ b/src/test/regress/sql/alter_table.sql @@ -419,6 +419,8 @@ insert into atacc1 (test) values (2); insert into atacc1 (test) values (4); -- try adding a unique oid constraint alter table atacc1 add constraint atacc_oid1 unique(oid); +-- try to create duplicates via alter table using - should fail +alter table atacc1 alter column test type integer using 0; drop table atacc1; -- let's do one where the unique constraint fails when added -- cgit v1.2.3