@@ -539,16 +539,23 @@ drop table atacc1;
539
539
create table atacc1 ( test int );
540
540
-- add a primary key constraint
541
541
alter table atacc1 add constraint atacc_test1 primary key (test);
542
- ERROR : Existing attribute "test" cannot be a PRIMARY KEY because it is not marked NOT NULL
542
+ NOTICE : ALTER TABLE / ADD PRIMARY KEY will create implicit index 'atacc_test1' for table 'atacc1'
543
543
-- insert first value
544
544
insert into atacc1 (test) values (2);
545
545
-- should fail
546
546
insert into atacc1 (test) values (2);
547
+ ERROR: Cannot insert a duplicate key into unique index atacc_test1
547
548
-- should succeed
548
549
insert into atacc1 (test) values (4);
549
550
-- inserting NULL should fail
550
551
insert into atacc1 (test) values(NULL);
551
- -- try adding a primary key oid constraint
552
+ ERROR: ExecInsert: Fail to add null value in not null attribute test
553
+ -- try adding a second primary key (should fail)
554
+ alter table atacc1 add constraint atacc_oid1 primary key(oid);
555
+ ERROR: ALTER TABLE / PRIMARY KEY multiple primary keys for table 'atacc1' are not allowed
556
+ -- drop first primary key constraint
557
+ alter table atacc1 drop constraint atacc_test1 restrict;
558
+ -- try adding a primary key on oid (should succeed)
552
559
alter table atacc1 add constraint atacc_oid1 primary key(oid);
553
560
NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index 'atacc_oid1' for table 'atacc1'
554
561
drop table atacc1;
@@ -559,7 +566,8 @@ insert into atacc1 (test) values (2);
559
566
insert into atacc1 (test) values (2);
560
567
-- add a primary key (fails)
561
568
alter table atacc1 add constraint atacc_test1 primary key (test);
562
- ERROR: Existing attribute "test" cannot be a PRIMARY KEY because it is not marked NOT NULL
569
+ NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index 'atacc_test1' for table 'atacc1'
570
+ ERROR: Cannot create unique index. Table contains non-unique values
563
571
insert into atacc1 (test) values (3);
564
572
drop table atacc1;
565
573
-- let's do another one where the primary key constraint fails when added
@@ -568,7 +576,8 @@ create table atacc1 ( test int );
568
576
insert into atacc1 (test) values (NULL);
569
577
-- add a primary key (fails)
570
578
alter table atacc1 add constraint atacc_test1 primary key (test);
571
- ERROR: Existing attribute "test" cannot be a PRIMARY KEY because it is not marked NOT NULL
579
+ NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index 'atacc_test1' for table 'atacc1'
580
+ ERROR: ALTER TABLE: Attribute "test" contains NULL values
572
581
insert into atacc1 (test) values (3);
573
582
drop table atacc1;
574
583
-- let's do one where the primary key constraint fails
@@ -582,17 +591,21 @@ drop table atacc1;
582
591
create table atacc1 ( test int, test2 int);
583
592
-- add a primary key constraint
584
593
alter table atacc1 add constraint atacc_test1 primary key (test, test2);
585
- ERROR : Existing attribute "test" cannot be a PRIMARY KEY because it is not marked NOT NULL
594
+ NOTICE : ALTER TABLE / ADD PRIMARY KEY will create implicit index 'atacc_test1' for table 'atacc1'
586
595
-- try adding a second primary key - should fail
587
596
alter table atacc1 add constraint atacc_test2 primary key (test);
588
- ERROR: Existing attribute "test" cannot be a PRIMARY KEY because it is not marked NOT NULL
597
+ ERROR: ALTER TABLE / PRIMARY KEY multiple primary keys for table 'atacc1' are not allowed
589
598
-- insert initial value
590
599
insert into atacc1 (test,test2) values (4,4);
591
600
-- should fail
592
601
insert into atacc1 (test,test2) values (4,4);
602
+ ERROR: Cannot insert a duplicate key into unique index atacc_test1
593
603
insert into atacc1 (test,test2) values (NULL,3);
604
+ ERROR: ExecInsert: Fail to add null value in not null attribute test
594
605
insert into atacc1 (test,test2) values (3, NULL);
606
+ ERROR: ExecInsert: Fail to add null value in not null attribute test2
595
607
insert into atacc1 (test,test2) values (NULL,NULL);
608
+ ERROR: ExecInsert: Fail to add null value in not null attribute test
596
609
-- should all succeed
597
610
insert into atacc1 (test,test2) values (4,5);
598
611
insert into atacc1 (test,test2) values (5,4);
0 commit comments