Index: src/test/regress/expected/alter_table.out
===================================================================
RCS file: /projects/cvsroot/pgsql/src/test/regress/expected/alter_table.out,v
retrieving revision 1.24
diff -c -r1.24 alter_table.out
*** src/test/regress/expected/alter_table.out	2001/10/12 00:07:15	1.24
--- src/test/regress/expected/alter_table.out	2001/10/27 09:46:05
***************
*** 448,450 ****
--- 448,509 ----
  drop table atacc3;
  drop table atacc2;
  drop table atacc1;
+ -- test unique constraint adding
+ create table atacc1 ( test int );
+ -- add a unique constraint
+ alter table atacc1 add constraint atacc_test1 unique (test);
+ NOTICE:  ALTER TABLE/UNIQUE will create implicit index 'atacc_test1' for table 'atacc1'
+ -- insert first value
+ insert into atacc1 (test) values (2);
+ -- should fail
+ insert into atacc1 (test) values (2);
+ ERROR:  Cannot insert a duplicate key into unique index atacc_test1
+ -- should succeed
+ insert into atacc1 (test) values (4);
+ -- try adding a unique oid constraint
+ alter table atacc1 add constraint atacc_oid1 unique(oid);
+ NOTICE:  ALTER TABLE/UNIQUE will create implicit index 'atacc_oid1' for table 'atacc1'
+ drop table atacc1;
+ -- let's do one where the unique constraint fails when added
+ create table atacc1 ( test int );
+ -- insert soon to be failing rows
+ insert into atacc1 (test) values (2);
+ insert into atacc1 (test) values (2);
+ -- add a unique constraint (fails)
+ alter table atacc1 add constraint atacc_test1 unique (test);
+  NOTICE:  ALTER TABLE/UNIQUE will create implicit index 'atacc_test1' for table 'atacc1'
+ ERROR:  Cannot create unique index. Table contains non-unique values
+ insert into atacc1 (test) values (3);
+ drop table atacc1;
+ -- let's do one where the unique contsraint fails
+ -- because the column doesn't exist
+ create table atacc1 ( test int );
+ -- add a unique constraint (fails)
+ alter table atacc1 add constraint atacc_test1 unique (test1);
+ ERROR:  ALTER TABLE: column "test1" named in key does not exist
+ drop table atacc1;
+ -- something a little more complicated
+ create table atacc1 ( test int, test2 int);
+ -- add a unique constraint
+ alter table atacc1 add constraint atacc_test1 unique (test, test2);
+ NOTICE:  ALTER TABLE/UNIQUE will create implicit index 'atacc_test1' for table 'atacc1'
+ -- insert initial value
+ insert into atacc1 (test,test2) values (4,4);
+ -- should fail
+ insert into atacc1 (test,test2) values (4,4);
+ ERROR:  Cannot insert a duplicate key into unique index atacc_test1
+ -- should all succeed
+ insert into atacc1 (test,test2) values (4,5);
+ insert into atacc1 (test,test2) values (5,4);
+ insert into atacc1 (test,test2) values (5,5);
+ drop table atacc1;
+ -- lets do some naming tests
+ create table atacc1 (test int, test2 int, unique(test));
+ NOTICE:  CREATE TABLE/UNIQUE will create implicit index 'atacc1_test_key' for table 'atacc1'
+ alter table atacc1 add unique (test2);
+ NOTICE:  ALTER TABLE/UNIQUE will create implicit index 'atacc1_test2_key' for table 'atacc1'
+ -- should fail for @@ second one @@
+ insert into atacc1 (test2, test) values (3, 3);
+ insert into atacc1 (test2, test) values (2, 3);
+ ERROR:  Cannot insert a duplicate key into unique index atacc1_test_key
+ drop table atacc1;
Index: src/test/regress/sql/alter_table.sql
===================================================================
RCS file: /projects/cvsroot/pgsql/src/test/regress/sql/alter_table.sql,v
retrieving revision 1.18
diff -c -r1.18 alter_table.sql
*** src/test/regress/sql/alter_table.sql	2001/05/30 13:00:03	1.18
--- src/test/regress/sql/alter_table.sql	2001/10/27 09:46:05
***************
*** 329,331 ****
--- 329,384 ----
  drop table atacc2;
  drop table atacc1;
  
+ -- test unique constraint adding
+ 
+ create table atacc1 ( test int );
+ -- add a unique constraint
+ alter table atacc1 add constraint atacc_test1 unique (test);
+ -- insert first value
+ insert into atacc1 (test) values (2);
+ -- should fail
+ insert into atacc1 (test) values (2);
+ -- should succeed
+ insert into atacc1 (test) values (4);
+ -- try adding a unique oid constraint
+ alter table atacc1 add constraint atacc_oid1 unique(oid);
+ drop table atacc1;
+ 
+ -- let's do one where the unique constraint fails when added
+ create table atacc1 ( test int );
+ -- insert soon to be failing rows
+ insert into atacc1 (test) values (2);
+ insert into atacc1 (test) values (2);
+ -- add a unique constraint (fails)
+ alter table atacc1 add constraint atacc_test1 unique (test);
+ insert into atacc1 (test) values (3);
+ drop table atacc1;
+ 
+ -- let's do one where the unique contsraint fails
+ -- because the column doesn't exist
+ create table atacc1 ( test int );
+ -- add a unique constraint (fails)
+ alter table atacc1 add constraint atacc_test1 unique (test1);
+ drop table atacc1;
+ 
+ -- something a little more complicated
+ create table atacc1 ( test int, test2 int);
+ -- add a unique constraint
+ alter table atacc1 add constraint atacc_test1 unique (test, test2);
+ -- insert initial value
+ insert into atacc1 (test,test2) values (4,4);
+ -- should fail
+ insert into atacc1 (test,test2) values (4,4);
+ -- should all succeed
+ insert into atacc1 (test,test2) values (4,5);
+ insert into atacc1 (test,test2) values (5,4);
+ insert into atacc1 (test,test2) values (5,5);
+ drop table atacc1;
+ 
+ -- lets do some naming tests
+ create table atacc1 (test int, test2 int, unique(test));
+ alter table atacc1 add unique (test2);
+ -- should fail for @@ second one @@
+ insert into atacc1 (test2, test) values (3, 3);
+ insert into atacc1 (test2, test) values (2, 3);
+ drop table atacc1;
