Commit 7cc8af55 authored by Bruce Momjian's avatar Bruce Momjian

Got "ADD" to appear only in ALTER TABLE and not CREATE TABLE

UNIQUE-PRIMARY KEY notice message.  This is what Christopher wanted from
his patch.
parent 434077c4
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.208 2001/11/04 02:41:09 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.209 2001/11/04 03:08:11 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1238,8 +1238,10 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1238,8 +1238,10 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
elog(ERROR, "%s: failed to make implicit index name", elog(ERROR, "%s: failed to make implicit index name",
cxt->stmtType); cxt->stmtType);
elog(NOTICE, "%s / %s will create implicit index '%s' for table '%s'", elog(NOTICE, "%s / %s%s will create implicit index '%s' for table '%s'",
cxt->stmtType, (index->primary ? "PRIMARY KEY" : "UNIQUE"), cxt->stmtType,
(strcmp(cxt->stmtType,"ALTER TABLE") == 0) ? "ADD " : "",
(index->primary ? "PRIMARY KEY" : "UNIQUE"),
index->idxname, cxt->relname); index->idxname, cxt->relname);
} }
} }
......
...@@ -452,7 +452,7 @@ drop table atacc1; ...@@ -452,7 +452,7 @@ drop table atacc1;
create table atacc1 ( test int ); create table atacc1 ( test int );
-- add a unique constraint -- add a unique constraint
alter table atacc1 add constraint atacc_test1 unique (test); alter table atacc1 add constraint atacc_test1 unique (test);
NOTICE: ALTER TABLE / UNIQUE will create implicit index 'atacc_test1' for table 'atacc1' NOTICE: ALTER TABLE / ADD UNIQUE will create implicit index 'atacc_test1' for table 'atacc1'
-- insert first value -- insert first value
insert into atacc1 (test) values (2); insert into atacc1 (test) values (2);
-- should fail -- should fail
...@@ -462,7 +462,7 @@ ERROR: Cannot insert a duplicate key into unique index atacc_test1 ...@@ -462,7 +462,7 @@ ERROR: Cannot insert a duplicate key into unique index atacc_test1
insert into atacc1 (test) values (4); insert into atacc1 (test) values (4);
-- try adding a unique oid constraint -- try adding a unique oid constraint
alter table atacc1 add constraint atacc_oid1 unique(oid); alter table atacc1 add constraint atacc_oid1 unique(oid);
NOTICE: ALTER TABLE / UNIQUE will create implicit index 'atacc_oid1' for table 'atacc1' NOTICE: ALTER TABLE / ADD UNIQUE will create implicit index 'atacc_oid1' for table 'atacc1'
drop table atacc1; drop table atacc1;
-- let's do one where the unique constraint fails when added -- let's do one where the unique constraint fails when added
create table atacc1 ( test int ); create table atacc1 ( test int );
...@@ -471,7 +471,7 @@ insert into atacc1 (test) values (2); ...@@ -471,7 +471,7 @@ insert into atacc1 (test) values (2);
insert into atacc1 (test) values (2); insert into atacc1 (test) values (2);
-- add a unique constraint (fails) -- add a unique constraint (fails)
alter table atacc1 add constraint atacc_test1 unique (test); alter table atacc1 add constraint atacc_test1 unique (test);
NOTICE: ALTER TABLE / UNIQUE will create implicit index 'atacc_test1' for table 'atacc1' NOTICE: ALTER TABLE / ADD UNIQUE will create implicit index 'atacc_test1' for table 'atacc1'
ERROR: Cannot create unique index. Table contains non-unique values ERROR: Cannot create unique index. Table contains non-unique values
insert into atacc1 (test) values (3); insert into atacc1 (test) values (3);
drop table atacc1; drop table atacc1;
...@@ -486,7 +486,7 @@ drop table atacc1; ...@@ -486,7 +486,7 @@ drop table atacc1;
create table atacc1 ( test int, test2 int); create table atacc1 ( test int, test2 int);
-- add a unique constraint -- add a unique constraint
alter table atacc1 add constraint atacc_test1 unique (test, test2); alter table atacc1 add constraint atacc_test1 unique (test, test2);
NOTICE: ALTER TABLE / UNIQUE will create implicit index 'atacc_test1' for table 'atacc1' NOTICE: ALTER TABLE / ADD UNIQUE will create implicit index 'atacc_test1' for table 'atacc1'
-- insert initial value -- insert initial value
insert into atacc1 (test,test2) values (4,4); insert into atacc1 (test,test2) values (4,4);
-- should fail -- should fail
...@@ -501,7 +501,7 @@ drop table atacc1; ...@@ -501,7 +501,7 @@ drop table atacc1;
create table atacc1 (test int, test2 int, unique(test)); create table atacc1 (test int, test2 int, unique(test));
NOTICE: CREATE TABLE / UNIQUE will create implicit index 'atacc1_test_key' for table 'atacc1' NOTICE: CREATE TABLE / UNIQUE will create implicit index 'atacc1_test_key' for table 'atacc1'
alter table atacc1 add unique (test2); alter table atacc1 add unique (test2);
NOTICE: ALTER TABLE / UNIQUE will create implicit index 'atacc1_test2_key' for table 'atacc1' NOTICE: ALTER TABLE / ADD UNIQUE will create implicit index 'atacc1_test2_key' for table 'atacc1'
-- should fail for @@ second one @@ -- should fail for @@ second one @@
insert into atacc1 (test2, test) values (3, 3); insert into atacc1 (test2, test) values (3, 3);
insert into atacc1 (test2, test) values (2, 3); insert into atacc1 (test2, test) values (2, 3);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment