Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4911c85

Browse files
committed
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.
1 parent74c2f8e commit4911c85

File tree

11 files changed

+172
-60
lines changed

11 files changed

+172
-60
lines changed

‎doc/src/sgml/ref/cluster.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/cluster.sgml,v 1.11 2001/09/03 12:57:49 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/cluster.sgml,v 1.12 2001/10/31 04:49:43 momjian Exp $
33
Postgres documentation
44
-->
55

@@ -189,7 +189,7 @@ SELECT <replaceable class="parameter">columnlist</replaceable> INTO TABLE <repla
189189
which uses the <productname>Postgres</productname> sorting code in
190190
the ORDER BY clause to match the index, and which is much faster for
191191
unordered data. You then drop the old table, use
192-
<command>ALTER TABLE/RENAME</command>
192+
<command>ALTER TABLE...RENAME</command>
193193
to rename <replaceable class="parameter">temp</replaceable> to the old name, and
194194
recreate any indexes. The only problem is that <acronym>OID</acronym>s
195195
will not be preserved. From then on, <command>CLUSTER</command> should be

‎src/backend/commands/command.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.147 2001/10/28 06:25:42 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.148 2001/10/31 04:49:43 momjian Exp $
1212
*
1313
* NOTES
1414
* The PerformAddAttribute() code, like most of the relation
@@ -1432,7 +1432,7 @@ AlterTableAddConstraint(char *relationName,
14321432
0,0,0);
14331433

14341434
if (!HeapTupleIsValid(indexTuple))
1435-
elog(ERROR,"ALTER TABLE/ADD CONSTRAINT: Index \"%u\" not found",
1435+
elog(ERROR,"ALTER TABLE /ADD CONSTRAINT: Index \"%u\" not found",
14361436
indexoid);
14371437
indexStruct= (Form_pg_index)GETSTRUCT(indexTuple);
14381438

@@ -1510,7 +1510,7 @@ AlterTableAddConstraint(char *relationName,
15101510
NIL);
15111511

15121512
/* Issue notice */
1513-
elog(NOTICE,"ALTER TABLE/ADD UNIQUE will create implicit index '%s' for table '%s'",
1513+
elog(NOTICE,"ALTER TABLE /ADD UNIQUE will create implicit index '%s' for table '%s'",
15141514
iname,relationName);
15151515
if (index_found)
15161516
elog(NOTICE,"Unique constraint supercedes existing index on relation \"%s\". Drop the existing index to remove redundancy.",relationName);

‎src/backend/parser/analyze.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
*$Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.205 2001/10/28 06:25:46 momjian Exp $
9+
*$Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.206 2001/10/31 04:49:43 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -1062,7 +1062,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
10621062
if (cxt->pkey!=NULL||
10631063
(OidIsValid(cxt->relOid)&&
10641064
relationHasPrimaryKey(cxt->relname)))
1065-
elog(ERROR,"%s/PRIMARY KEY multiple primary keys"
1065+
elog(ERROR,"%s /PRIMARY KEY multiple primary keys"
10661066
" for table '%s' are not allowed",
10671067
cxt->stmtType,cxt->relname);
10681068
cxt->pkey=index;
@@ -1291,8 +1291,8 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
12911291
elog(ERROR,"%s: failed to make implicit index name",
12921292
cxt->stmtType);
12931293

1294-
elog(NOTICE,"%s/%s will create implicit index '%s' for table '%s'",
1295-
cxt->stmtType, (index->primary ?"PRIMARY KEY" :"UNIQUE"),
1294+
elog(NOTICE,"%s /%s will create implicit index '%s' for table '%s'",
1295+
cxt->stmtType, (index->primary ?"ADDPRIMARY KEY" :"ADDUNIQUE"),
12961296
index->idxname,cxt->relname);
12971297
}
12981298
}

‎src/backend/parser/gram.y

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.270 2001/10/23 02:50:41 momjian Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.271 2001/10/31 04:49:43 momjian Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -1300,7 +1300,7 @@ columnDef: ColId Typename ColQualList opt_collate
13001300
n->constraints =$3;
13011301

13021302
if ($4 !=NULL)
1303-
elog(NOTICE,"CREATE TABLE/COLLATE %s not yet implemented"
1303+
elog(NOTICE,"CREATE TABLE /COLLATE %s not yet implemented"
13041304
"; clause ignored", $4);
13051305

13061306
$$ = (Node *)n;
@@ -1611,7 +1611,7 @@ CreateAsStmt: CREATE OptTemp TABLE relation_name OptCreateAs AS SelectStmt
16111611
*/
16121612
SelectStmt *n = findLeftmostSelect((SelectStmt *)$7);
16131613
if (n->into !=NULL)
1614-
elog(ERROR,"CREATE TABLE/AS SELECT may not specify INTO");
1614+
elog(ERROR,"CREATE TABLE /AS SELECT may not specify INTO");
16151615
n->istemp =$2;
16161616
n->into =$4;
16171617
if ($5 != NIL)
@@ -2171,7 +2171,7 @@ FetchStmt: FETCH direction fetch_how_many from_in name
21712171
if ($2 == RELATIVE)
21722172
{
21732173
if ($3 ==0)
2174-
elog(ERROR,"FETCH/RELATIVE at current position is not supported");
2174+
elog(ERROR,"FETCH /RELATIVE at current position is not supported");
21752175
$2 = FORWARD;
21762176
}
21772177
if ($3 <0)
@@ -2299,7 +2299,7 @@ direction:FORWARD{ $$ = FORWARD; }
22992299
|RELATIVE{$$ = RELATIVE; }
23002300
|ABSOLUTE
23012301
{
2302-
elog(NOTICE,"FETCH/ABSOLUTE not supported, using RELATIVE");
2302+
elog(NOTICE,"FETCH /ABSOLUTE not supported, using RELATIVE");
23032303
$$ = RELATIVE;
23042304
}
23052305
;
@@ -2605,12 +2605,12 @@ opt_arg: IN
26052605
}
26062606
|OUT
26072607
{
2608-
elog(ERROR,"CREATE FUNCTION/OUT parameters are not supported");
2608+
elog(ERROR,"CREATE FUNCTION /OUT parameters are not supported");
26092609
$$ =TRUE;
26102610
}
26112611
|INOUT
26122612
{
2613-
elog(ERROR,"CREATE FUNCTION/INOUT parameters are not supported");
2613+
elog(ERROR,"CREATE FUNCTION /INOUT parameters are not supported");
26142614
$$ =FALSE;
26152615
}
26162616
;
@@ -2955,7 +2955,7 @@ opt_chain: AND NO CHAIN
29552955
* if they don't support it. So we can't just ignore it.
29562956
* - thomas 2000-08-06
29572957
*/
2958-
elog(ERROR,"COMMIT/CHAIN not yet supported");
2958+
elog(ERROR,"COMMIT /CHAIN not yet supported");
29592959
$$ =TRUE;
29602960
}
29612961
;
@@ -6113,7 +6113,7 @@ mapTargetColumns(List *src, List *dst)
61136113
ResTarget *d;
61146114

61156115
if (length(src) !=length(dst))
6116-
elog(ERROR,"CREATE TABLE/AS SELECT has mismatched column count");
6116+
elog(ERROR,"CREATE TABLE /AS SELECT has mismatched column count");
61176117

61186118
while ((src != NIL) && (dst != NIL))
61196119
{

‎src/interfaces/ecpg/lib/connect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.13 2001/10/25 05:50:11 momjian Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.14 2001/10/31 04:49:44 momjian Exp $ */
22

33
#include"postgres_fe.h"
44

@@ -205,7 +205,7 @@ ECPGnoticeProcessor(void *arg, const char *message)
205205
/* these are harmless - do nothing */
206206

207207
/*
208-
* NOTICE:CREATE TABLE/PRIMARY KEY will create implicit index '*'
208+
* NOTICE:CREATE TABLE /PRIMARY KEY will create implicit index '*'
209209
* for table '*'
210210
*/
211211

‎src/interfaces/ecpg/preproc/preproc.y

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,11 +1087,11 @@ OptTemp: TEMPORARY{ $$ = make_str("temporary"); }
10871087
|LOCALTEMPORARY{$$ = make_str("local temporary"); }
10881088
|LOCALTEMP{$$ = make_str("local temp"); }
10891089
|GLOBALTEMPORARY{
1090-
mmerror(ET_NOTICE,"Currently unsupported CREATE TABLE/GLOBAL TEMPORARY will be passed to backend");
1090+
mmerror(ET_NOTICE,"Currently unsupported CREATE TABLE /GLOBAL TEMPORARY will be passed to backend");
10911091
$$ = make_str("global temporary");
10921092
}
10931093
|GLOBALTEMP{
1094-
mmerror(ET_NOTICE,"Currently unsupported CREATE TABLE/GLOBAL TEMP will be passed to backend");
1094+
mmerror(ET_NOTICE,"Currently unsupported CREATE TABLE /GLOBAL TEMP will be passed to backend");
10951095
$$ = make_str("global temp");
10961096
}
10971097
|/*EMPTY*/{$$ = EMPTY; }
@@ -1116,7 +1116,7 @@ columnDef: ColId Typename ColQualList opt_collate
11161116
{
11171117
if (strlen($4) >0)
11181118
{
1119-
sprintf(errortext,"Currently unsupported CREATE TABLE/COLLATE %s will be passed to backend", $4);
1119+
sprintf(errortext,"Currently unsupported CREATE TABLE /COLLATE %s will be passed to backend", $4);
11201120
mmerror(ET_NOTICE, errortext);
11211121
}
11221122
$$ = cat_str(4,$1,$2,$3,$4);
@@ -1278,7 +1278,7 @@ CreateAsStmt: CREATE OptTemp TABLE relation_name OptCreateAs AS
12781278
{ FoundInto =0; }SelectStmt
12791279
{
12801280
if (FoundInto ==1)
1281-
mmerror(ET_ERROR,"CREATE TABLE/AS SELECT may not specify INTO");
1281+
mmerror(ET_ERROR,"CREATE TABLE /AS SELECT may not specify INTO");
12821282

12831283
$$ = cat_str(7, make_str("create"),$2, make_str("table"),$4,$5, make_str("as"),$8);
12841284
}
@@ -2626,12 +2626,12 @@ OptTempTableName: TEMPORARY opt_table relation_name
26262626
}
26272627
|GLOBALTEMPORARYopt_tablerelation_name
26282628
{
2629-
mmerror(ET_NOTICE,"Currently unsupported CREATE TABLE/GLOBAL TEMPORARY will be passed to backend");
2629+
mmerror(ET_NOTICE,"Currently unsupported CREATE TABLE /GLOBAL TEMPORARY will be passed to backend");
26302630
$$ = cat_str(3, make_str("global temporary"),$3,$4);
26312631
}
26322632
|GLOBALTEMPopt_tablerelation_name
26332633
{
2634-
mmerror(ET_NOTICE,"Currently unsupported CREATE TABLE/GLOBAL TEMP will be passed to backend");
2634+
mmerror(ET_NOTICE,"Currently unsupported CREATE TABLE /GLOBAL TEMP will be passed to backend");
26352635
$$ = cat_str(3, make_str("global temp"),$3,$4);
26362636
}
26372637
|TABLErelation_name

‎src/test/regress/expected/alter_table.out

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,10 @@ SELECT unique1 FROM tenk1 WHERE unique1 < 5;
271271

272272
-- FOREIGN KEY CONSTRAINT adding TEST
273273
CREATE TABLE tmp2 (a int primary key);
274-
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'tmp2_pkey' for table 'tmp2'
274+
NOTICE: CREATE TABLE /PRIMARY KEY will create implicit index 'tmp2_pkey' for table 'tmp2'
275275
CREATE TABLE tmp3 (a int, b int);
276276
CREATE TABLE tmp4 (a int, b int, unique(a,b));
277-
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'tmp4_a_key' for table 'tmp4'
277+
NOTICE: CREATE TABLE / ADDUNIQUE will create implicit index 'tmp4_a_key' for table 'tmp4'
278278
CREATE TABLE tmp5 (a int, b int);
279279
-- Insert rows into tmp2 (pktable)
280280
INSERT INTO tmp2 values (1);
@@ -317,7 +317,7 @@ DROP TABLE tmp2;
317317
-- Note: these tables are TEMP to avoid name conflicts when this test
318318
-- is run in parallel with foreign_key.sql.
319319
CREATE TEMP TABLE PKTABLE (ptest1 int PRIMARY KEY);
320-
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'pktable_pkey' for table 'pktable'
320+
NOTICE: CREATE TABLE /PRIMARY KEY will create implicit index 'pktable_pkey' for table 'pktable'
321321
CREATE TEMP TABLE FKTABLE (ftest1 text);
322322
-- This next should fail, because text=int does not exist
323323
ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable;
@@ -345,7 +345,7 @@ NOTICE: DROP TABLE implicitly drops referential integrity trigger from table "f
345345
DROP TABLE fktable;
346346
CREATE TEMP TABLE PKTABLE (ptest1 int, ptest2 text,
347347
PRIMARY KEY(ptest1, ptest2));
348-
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'pktable_pkey' for table 'pktable'
348+
NOTICE: CREATE TABLE /PRIMARY KEY will create implicit index 'pktable_pkey' for table 'pktable'
349349
-- This should fail, because we just chose really odd types
350350
CREATE TEMP TABLE FKTABLE (ftest1 cidr, ftest2 datetime);
351351
ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1, ftest2) references pktable;
@@ -448,3 +448,62 @@ insert into atacc3 (test2) values (3);
448448
drop table atacc3;
449449
drop table atacc2;
450450
drop table atacc1;
451+
-- test unique constraint adding
452+
create table atacc1 ( test int );
453+
-- add a unique constraint
454+
alter table atacc1 add constraint atacc_test1 unique (test);
455+
NOTICE: ALTER TABLE/UNIQUE will create implicit index 'atacc_test1' for table 'atacc1'
456+
-- insert first value
457+
insert into atacc1 (test) values (2);
458+
-- should fail
459+
insert into atacc1 (test) values (2);
460+
ERROR: Cannot insert a duplicate key into unique index atacc_test1
461+
-- should succeed
462+
insert into atacc1 (test) values (4);
463+
-- try adding a unique oid constraint
464+
alter table atacc1 add constraint atacc_oid1 unique(oid);
465+
NOTICE: ALTER TABLE/UNIQUE will create implicit index 'atacc_oid1' for table 'atacc1'
466+
drop table atacc1;
467+
-- let's do one where the unique constraint fails when added
468+
create table atacc1 ( test int );
469+
-- insert soon to be failing rows
470+
insert into atacc1 (test) values (2);
471+
insert into atacc1 (test) values (2);
472+
-- add a unique constraint (fails)
473+
alter table atacc1 add constraint atacc_test1 unique (test);
474+
NOTICE: ALTER TABLE/UNIQUE will create implicit index 'atacc_test1' for table 'atacc1'
475+
ERROR: Cannot create unique index. Table contains non-unique values
476+
insert into atacc1 (test) values (3);
477+
drop table atacc1;
478+
-- let's do one where the unique contsraint fails
479+
-- because the column doesn't exist
480+
create table atacc1 ( test int );
481+
-- add a unique constraint (fails)
482+
alter table atacc1 add constraint atacc_test1 unique (test1);
483+
ERROR: ALTER TABLE: column "test1" named in key does not exist
484+
drop table atacc1;
485+
-- something a little more complicated
486+
create table atacc1 ( test int, test2 int);
487+
-- add a unique constraint
488+
alter table atacc1 add constraint atacc_test1 unique (test, test2);
489+
NOTICE: ALTER TABLE/UNIQUE will create implicit index 'atacc_test1' for table 'atacc1'
490+
-- insert initial value
491+
insert into atacc1 (test,test2) values (4,4);
492+
-- should fail
493+
insert into atacc1 (test,test2) values (4,4);
494+
ERROR: Cannot insert a duplicate key into unique index atacc_test1
495+
-- should all succeed
496+
insert into atacc1 (test,test2) values (4,5);
497+
insert into atacc1 (test,test2) values (5,4);
498+
insert into atacc1 (test,test2) values (5,5);
499+
drop table atacc1;
500+
-- lets do some naming tests
501+
create table atacc1 (test int, test2 int, unique(test));
502+
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'atacc1_test_key' for table 'atacc1'
503+
alter table atacc1 add unique (test2);
504+
NOTICE: ALTER TABLE/UNIQUE will create implicit index 'atacc1_test2_key' for table 'atacc1'
505+
-- should fail for @@ second one @@
506+
insert into atacc1 (test2, test) values (3, 3);
507+
insert into atacc1 (test2, test) values (2, 3);
508+
ERROR: Cannot insert a duplicate key into unique index atacc1_test_key
509+
drop table atacc1;

‎src/test/regress/expected/create_misc.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ INSERT INTO iportaltest (i, d, p)
137137
---
138138
CREATE TABLE serialTest (f1 text, f2 serial);
139139
NOTICE: CREATE TABLE will create implicit sequence 'serialtest_f2_seq' for SERIAL column 'serialtest.f2'
140-
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'serialtest_f2_key' for table 'serialtest'
140+
NOTICE: CREATE TABLE / ADDUNIQUE will create implicit index 'serialtest_f2_key' for table 'serialtest'
141141
INSERT INTO serialTest VALUES ('foo');
142142
INSERT INTO serialTest VALUES ('bar');
143143
INSERT INTO serialTest VALUES ('force', 100);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp