1
Fork 0
kantodb/testdata/sql/create_index_unique_nulls_not_distinct.slt

28 lines
970 B
Text

statement ok
CREATE TABLE myschema.mytable (one BIGINT NOT NULL, two BIGINT, PRIMARY KEY(one));
statement ok
CREATE UNIQUE INDEX mytable__idx__two ON myschema.mytable (two) NULLS NOT DISTINCT;
statement ok
INSERT INTO myschema.mytable (one, two) VALUES (1, 2);
statement ok
INSERT INTO myschema.mytable (one, two) VALUES (3, 4);
# TODO better error
#
# Postgres says:
# ```
# ERROR: duplicate key value violates unique constraint "mytable__idx__two"
# DETAIL: Key (two)=(2) already exists.
# ```
statement error ^Execution error: execution/9uzcseehsg8xy: insert into index: table_id=3, index_id=1: conflict on unique index$
INSERT INTO myschema.mytable (one, two) VALUES (2, 2);
statement ok
INSERT INTO myschema.mytable (one, two) VALUES (5, NULL);
# Nulls are not distinct.
statement error ^Execution error: execution/9uzcseehsg8xy: insert into index: table_id=3, index_id=1: conflict on unique index$
INSERT INTO myschema.mytable (one, two) VALUES (6, NULL);