mirror of
https://github.com/postgres/postgres.git
synced 2025-05-21 15:54:08 +03:00
Add ALTER TABLE ADD UNIQUE regression tests from Christopher Kings-Lynne.
Add space between slash for ALTER TABLE / ADD .... Regression and *.po updates to follow.
This commit is contained in:
parent
74c2f8e729
commit
4911c85e86
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/cluster.sgml,v 1.11 2001/09/03 12:57:49 petere Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/cluster.sgml,v 1.12 2001/10/31 04:49:43 momjian Exp $
|
||||||
Postgres documentation
|
Postgres documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ SELECT <replaceable class="parameter">columnlist</replaceable> INTO TABLE <repla
|
|||||||
which uses the <productname>Postgres</productname> sorting code in
|
which uses the <productname>Postgres</productname> sorting code in
|
||||||
the ORDER BY clause to match the index, and which is much faster for
|
the ORDER BY clause to match the index, and which is much faster for
|
||||||
unordered data. You then drop the old table, use
|
unordered data. You then drop the old table, use
|
||||||
<command>ALTER TABLE/RENAME</command>
|
<command>ALTER TABLE...RENAME</command>
|
||||||
to rename <replaceable class="parameter">temp</replaceable> to the old name, and
|
to rename <replaceable class="parameter">temp</replaceable> to the old name, and
|
||||||
recreate any indexes. The only problem is that <acronym>OID</acronym>s
|
recreate any indexes. The only problem is that <acronym>OID</acronym>s
|
||||||
will not be preserved. From then on, <command>CLUSTER</command> should be
|
will not be preserved. From then on, <command>CLUSTER</command> should be
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.147 2001/10/28 06:25:42 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.148 2001/10/31 04:49:43 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* The PerformAddAttribute() code, like most of the relation
|
* The PerformAddAttribute() code, like most of the relation
|
||||||
|
@ -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.205 2001/10/28 06:25:46 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.206 2001/10/31 04:49:43 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -1292,7 +1292,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
|
|||||||
cxt->stmtType);
|
cxt->stmtType);
|
||||||
|
|
||||||
elog(NOTICE, "%s / %s will create implicit index '%s' for table '%s'",
|
elog(NOTICE, "%s / %s will create implicit index '%s' for table '%s'",
|
||||||
cxt->stmtType, (index->primary ? "PRIMARY KEY" : "UNIQUE"),
|
cxt->stmtType, (index->primary ? "ADD PRIMARY KEY" : "ADD UNIQUE"),
|
||||||
index->idxname, cxt->relname);
|
index->idxname, cxt->relname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.270 2001/10/23 02:50:41 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.271 2001/10/31 04:49:43 momjian Exp $
|
||||||
*
|
*
|
||||||
* HISTORY
|
* HISTORY
|
||||||
* AUTHOR DATE MAJOR EVENT
|
* AUTHOR DATE MAJOR EVENT
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.13 2001/10/25 05:50:11 momjian Exp $ */
|
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.14 2001/10/31 04:49:44 momjian Exp $ */
|
||||||
|
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ CREATE TABLE tmp2 (a int primary key);
|
|||||||
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'tmp2_pkey' for table 'tmp2'
|
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'tmp2_pkey' for table 'tmp2'
|
||||||
CREATE TABLE tmp3 (a int, b int);
|
CREATE TABLE tmp3 (a int, b int);
|
||||||
CREATE TABLE tmp4 (a int, b int, unique(a,b));
|
CREATE TABLE tmp4 (a int, b int, unique(a,b));
|
||||||
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'tmp4_a_key' for table 'tmp4'
|
NOTICE: CREATE TABLE / ADD UNIQUE will create implicit index 'tmp4_a_key' for table 'tmp4'
|
||||||
CREATE TABLE tmp5 (a int, b int);
|
CREATE TABLE tmp5 (a int, b int);
|
||||||
-- Insert rows into tmp2 (pktable)
|
-- Insert rows into tmp2 (pktable)
|
||||||
INSERT INTO tmp2 values (1);
|
INSERT INTO tmp2 values (1);
|
||||||
@ -448,3 +448,62 @@ insert into atacc3 (test2) values (3);
|
|||||||
drop table atacc3;
|
drop table atacc3;
|
||||||
drop table atacc2;
|
drop table atacc2;
|
||||||
drop table atacc1;
|
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;
|
||||||
|
@ -137,7 +137,7 @@ INSERT INTO iportaltest (i, d, p)
|
|||||||
---
|
---
|
||||||
CREATE TABLE serialTest (f1 text, f2 serial);
|
CREATE TABLE serialTest (f1 text, f2 serial);
|
||||||
NOTICE: CREATE TABLE will create implicit sequence 'serialtest_f2_seq' for SERIAL column 'serialtest.f2'
|
NOTICE: CREATE TABLE will create implicit sequence 'serialtest_f2_seq' for SERIAL column 'serialtest.f2'
|
||||||
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'serialtest_f2_key' for table 'serialtest'
|
NOTICE: CREATE TABLE / ADD UNIQUE will create implicit index 'serialtest_f2_key' for table 'serialtest'
|
||||||
INSERT INTO serialTest VALUES ('foo');
|
INSERT INTO serialTest VALUES ('foo');
|
||||||
INSERT INTO serialTest VALUES ('bar');
|
INSERT INTO serialTest VALUES ('bar');
|
||||||
INSERT INTO serialTest VALUES ('force', 100);
|
INSERT INTO serialTest VALUES ('force', 100);
|
||||||
|
@ -705,7 +705,7 @@ ERROR: table "fktable_fail2" does not exist
|
|||||||
DROP TABLE PKTABLE;
|
DROP TABLE PKTABLE;
|
||||||
-- Test for referencing column number smaller than referenced constraint
|
-- Test for referencing column number smaller than referenced constraint
|
||||||
CREATE TABLE PKTABLE (ptest1 int, ptest2 int, UNIQUE(ptest1, ptest2));
|
CREATE TABLE PKTABLE (ptest1 int, ptest2 int, UNIQUE(ptest1, ptest2));
|
||||||
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'pktable_ptest1_key' for table 'pktable'
|
NOTICE: CREATE TABLE / ADD UNIQUE will create implicit index 'pktable_ptest1_key' for table 'pktable'
|
||||||
CREATE TABLE FKTABLE_FAIL1 (ftest1 int REFERENCES pktable(ptest1));
|
CREATE TABLE FKTABLE_FAIL1 (ftest1 int REFERENCES pktable(ptest1));
|
||||||
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||||
ERROR: UNIQUE constraint matching given keys for referenced table "pktable" not found
|
ERROR: UNIQUE constraint matching given keys for referenced table "pktable" not found
|
||||||
@ -824,7 +824,7 @@ ERROR: Unable to identify an operator '=' for types 'text' and 'integer'
|
|||||||
create table pktable_base (base1 int not null);
|
create table pktable_base (base1 int not null);
|
||||||
create table pktable (ptest1 int, primary key(base1), unique(base1, ptest1)) inherits (pktable_base);
|
create table pktable (ptest1 int, primary key(base1), unique(base1, ptest1)) inherits (pktable_base);
|
||||||
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'pktable_pkey' for table 'pktable'
|
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'pktable_pkey' for table 'pktable'
|
||||||
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'pktable_base1_key' for table 'pktable'
|
NOTICE: CREATE TABLE / ADD UNIQUE will create implicit index 'pktable_base1_key' for table 'pktable'
|
||||||
create table fktable (ftest1 int references pktable(base1));
|
create table fktable (ftest1 int references pktable(base1));
|
||||||
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||||
-- now some ins, upd, del
|
-- now some ins, upd, del
|
||||||
|
@ -330,7 +330,7 @@ DROP TABLE PRIMARY_TBL;
|
|||||||
-- Unique keys
|
-- Unique keys
|
||||||
--
|
--
|
||||||
CREATE TABLE UNIQUE_TBL (i int UNIQUE, t text);
|
CREATE TABLE UNIQUE_TBL (i int UNIQUE, t text);
|
||||||
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'unique_tbl_i_key' for table 'unique_tbl'
|
NOTICE: CREATE TABLE / ADD UNIQUE will create implicit index 'unique_tbl_i_key' for table 'unique_tbl'
|
||||||
INSERT INTO UNIQUE_TBL VALUES (1, 'one');
|
INSERT INTO UNIQUE_TBL VALUES (1, 'one');
|
||||||
INSERT INTO UNIQUE_TBL VALUES (2, 'two');
|
INSERT INTO UNIQUE_TBL VALUES (2, 'two');
|
||||||
INSERT INTO UNIQUE_TBL VALUES (1, 'three');
|
INSERT INTO UNIQUE_TBL VALUES (1, 'three');
|
||||||
@ -353,7 +353,7 @@ SELECT '' AS five, * FROM UNIQUE_TBL;
|
|||||||
DROP TABLE UNIQUE_TBL;
|
DROP TABLE UNIQUE_TBL;
|
||||||
CREATE TABLE UNIQUE_TBL (i int, t text,
|
CREATE TABLE UNIQUE_TBL (i int, t text,
|
||||||
UNIQUE(i,t));
|
UNIQUE(i,t));
|
||||||
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'unique_tbl_i_key' for table 'unique_tbl'
|
NOTICE: CREATE TABLE / ADD UNIQUE will create implicit index 'unique_tbl_i_key' for table 'unique_tbl'
|
||||||
INSERT INTO UNIQUE_TBL VALUES (1, 'one');
|
INSERT INTO UNIQUE_TBL VALUES (1, 'one');
|
||||||
INSERT INTO UNIQUE_TBL VALUES (2, 'two');
|
INSERT INTO UNIQUE_TBL VALUES (2, 'two');
|
||||||
INSERT INTO UNIQUE_TBL VALUES (1, 'three');
|
INSERT INTO UNIQUE_TBL VALUES (1, 'three');
|
||||||
|
@ -329,3 +329,56 @@ drop table atacc3;
|
|||||||
drop table atacc2;
|
drop table atacc2;
|
||||||
drop table atacc1;
|
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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user