【fixbug】唯一索引的索引名不支持key关键字

This commit is contained in:
yuhuanhuan
2022-09-22 11:30:07 +08:00
parent 967eafed4e
commit 36959a919f
5 changed files with 154 additions and 1 deletions

View File

@ -7298,6 +7298,15 @@ ConstraintElem:
errmsg("UNIQUE name is not yet supported in distributed database.")));
#endif
if (u_sess->attr.attr_sql.sql_compatibility == B_FORMAT) {
if (strcasecmp($2, "index") == 0 || strcasecmp($2, "key") == 0) {
const char* message = "index/key cannot be used as unique name.";
InsertErrorMessage(message, u_sess->plsql_cxt.plpgsql_yylloc);
ereport(errstate,
(errmodule(MOD_PARSER),
errcode(ERRCODE_SYNTAX_ERROR),
errmsg("index/key cannot be used as unique name."),
parser_errposition(@1)));
}
Constraint *n = makeNode(Constraint);
n->contype = CONSTR_UNIQUE;
n->location = @1;

View File

@ -2018,6 +2018,18 @@ Indexes:
Has OIDs: no
Options: orientation=row, compression=no
drop table test_unique;
-- test unreserved_keyword index and key
create table test_unique(f31 int, f32 varchar(20));
-- error
alter table test_unique add constraint con_t_unique unique key using btree(f31);
ERROR: index/key cannot be used as unique name.
LINE 1: ...ter table test_unique add constraint con_t_unique unique key...
^
alter table test_unique add constraint con_t_unique unique index using btree(f31);
ERROR: index/key cannot be used as unique name.
LINE 1: ...ter table test_unique add constraint con_t_unique unique ind...
^
drop table test_unique;
-- test primary key is only supported in B mode
-- alter table
@ -2718,5 +2730,29 @@ Number of partitions: 4 (View pg_partition to check each partition range.)
Has OIDs: no
Options: orientation=row, compression=no
drop table test_p_unique;
-- test unreserved_keyword index and key
CREATE TABLE test_p_unique
(
f1 INTEGER,
f2 INTEGER,
f3 INTEGER
)
PARTITION BY RANGE(f1)
(
PARTITION P1 VALUES LESS THAN(2450815),
PARTITION P2 VALUES LESS THAN(2451179),
PARTITION P3 VALUES LESS THAN(2451544),
PARTITION P4 VALUES LESS THAN(MAXVALUE)
);
-- error
alter table test_p_unique add constraint con_t_unique unique key using btree(f1);
ERROR: index/key cannot be used as unique name.
LINE 1: ...r table test_p_unique add constraint con_t_unique unique key...
^
alter table test_p_unique add constraint con_t_unique unique index using btree(f1);
ERROR: index/key cannot be used as unique name.
LINE 1: ...r table test_p_unique add constraint con_t_unique unique ind...
^
drop table test_p_unique;
\c postgres

View File

@ -1427,6 +1427,16 @@ Has OIDs: no
Options: orientation=row, compression=no
drop table test_unique;
-- test unreserved_keyword index and key
-- error
create table test_unique(f31 int, f32 varchar(20), constraint con_t_unique unique key using btree(f31));
ERROR: index/key cannot be used as unique name.
LINE 1: ...f31 int, f32 varchar(20), constraint con_t_unique unique key...
^
create table test_unique(f31 int, f32 varchar(20), constraint con_t_unique unique index using btree(f31));
ERROR: index/key cannot be used as unique name.
LINE 1: ...f31 int, f32 varchar(20), constraint con_t_unique unique ind...
^
-- partition table
-- test primary key in M mode
-- test [index_type]
@ -2057,4 +2067,40 @@ ERROR: partition table does not support expression index
\d+ test_p_unique
drop table test_p_unique;
ERROR: table "test_p_unique" does not exist
-- test unreserved_keyword index and key
-- error
CREATE TABLE test_p_unique
(
f1 INTEGER,
f2 INTEGER,
f3 INTEGER,
constraint con_t_unique unique key using btree(f1)
)
PARTITION BY RANGE(f1)
(
PARTITION P1 VALUES LESS THAN(2450815),
PARTITION P2 VALUES LESS THAN(2451179),
PARTITION P3 VALUES LESS THAN(2451544),
PARTITION P4 VALUES LESS THAN(MAXVALUE)
);
ERROR: index/key cannot be used as unique name.
LINE 6: constraint con_t_unique unique key using btree(f1)
^
CREATE TABLE test_p_unique
(
f1 INTEGER,
f2 INTEGER,
f3 INTEGER,
constraint con_t_unique unique index using btree(f1)
)
PARTITION BY RANGE(f1)
(
PARTITION P1 VALUES LESS THAN(2450815),
PARTITION P2 VALUES LESS THAN(2451179),
PARTITION P3 VALUES LESS THAN(2451544),
PARTITION P4 VALUES LESS THAN(MAXVALUE)
);
ERROR: index/key cannot be used as unique name.
LINE 6: constraint con_t_unique unique index using btree(f1)
^
\c postgres

View File

@ -890,6 +890,13 @@ alter table test_unique add unique using index idx_unique;
\d+ test_unique
drop table test_unique;
-- test unreserved_keyword index and key
create table test_unique(f31 int, f32 varchar(20));
-- error
alter table test_unique add constraint con_t_unique unique key using btree(f31);
alter table test_unique add constraint con_t_unique unique index using btree(f31);
drop table test_unique;
-- test primary key is only supported in B mode
-- alter table
CREATE TABLE test_p_primary
@ -1302,7 +1309,6 @@ alter table test_p_unique add unique using index idx_unique;
\d+ test_p_unique
drop table test_p_unique;
CREATE TABLE test_p_unique
(
f1 INTEGER,
@ -1321,5 +1327,23 @@ alter table test_p_unique add unique using index idx_unique;
\d+ test_p_unique
drop table test_p_unique;
-- test unreserved_keyword index and key
CREATE TABLE test_p_unique
(
f1 INTEGER,
f2 INTEGER,
f3 INTEGER
)
PARTITION BY RANGE(f1)
(
PARTITION P1 VALUES LESS THAN(2450815),
PARTITION P2 VALUES LESS THAN(2451179),
PARTITION P3 VALUES LESS THAN(2451544),
PARTITION P4 VALUES LESS THAN(MAXVALUE)
);
-- error
alter table test_p_unique add constraint con_t_unique unique key using btree(f1);
alter table test_p_unique add constraint con_t_unique unique index using btree(f1);
drop table test_p_unique;
\c postgres

View File

@ -998,6 +998,11 @@ create table test_unique(f31 int, f32 varchar(20), unique ((f31 * 2 + 1) desc, (
\d+ test_unique
drop table test_unique;
-- test unreserved_keyword index and key
-- error
create table test_unique(f31 int, f32 varchar(20), constraint con_t_unique unique key using btree(f31));
create table test_unique(f31 int, f32 varchar(20), constraint con_t_unique unique index using btree(f31));
-- partition table
-- test primary key in M mode
-- test [index_type]
@ -1408,4 +1413,37 @@ PARTITION BY RANGE(f1)
\d+ test_p_unique
drop table test_p_unique;
-- test unreserved_keyword index and key
-- error
CREATE TABLE test_p_unique
(
f1 INTEGER,
f2 INTEGER,
f3 INTEGER,
constraint con_t_unique unique key using btree(f1)
)
PARTITION BY RANGE(f1)
(
PARTITION P1 VALUES LESS THAN(2450815),
PARTITION P2 VALUES LESS THAN(2451179),
PARTITION P3 VALUES LESS THAN(2451544),
PARTITION P4 VALUES LESS THAN(MAXVALUE)
);
CREATE TABLE test_p_unique
(
f1 INTEGER,
f2 INTEGER,
f3 INTEGER,
constraint con_t_unique unique index using btree(f1)
)
PARTITION BY RANGE(f1)
(
PARTITION P1 VALUES LESS THAN(2450815),
PARTITION P2 VALUES LESS THAN(2451179),
PARTITION P3 VALUES LESS THAN(2451544),
PARTITION P4 VALUES LESS THAN(MAXVALUE)
);
\c postgres