Files
email-tracker/external/duckdb/test/sql/constraints/unique/test_unique.test
2025-10-24 19:21:19 -05:00

91 lines
1.6 KiB
SQL

# name: test/sql/constraints/unique/test_unique.test
# description: Single UNIQUE constraint
# group: [unique]
statement ok
SET default_null_order='nulls_first';
statement ok
CREATE TABLE integers(i INTEGER UNIQUE, j INTEGER)
# insert unique values
statement ok
INSERT INTO integers VALUES (3, 4), (2, 5)
query II
SELECT * FROM integers
----
3 4
2 5
# insert a duplicate value as part of a chain of values, this should fail
statement error
INSERT INTO integers VALUES (6, 6), (3, 4);
----
statement ok
INSERT INTO integers VALUES (NULL, 6), (NULL, 7)
# but if we try to replace them like this it's going to fail
statement error
UPDATE integers SET i=77 WHERE i IS NULL
----
query II
SELECT * FROM integers ORDER BY i, j
----
NULL 6
NULL 7
2 5
3 4
# we can replace them like this though
statement ok
UPDATE integers SET i=77 WHERE i IS NULL AND j=6
query II
SELECT * FROM integers ORDER BY i, j
----
NULL 7
2 5
3 4
77 6
statement ok
INSERT INTO integers VALUES (NULL, 6), (NULL, 7)
statement ok
INSERT INTO integers VALUES (NULL, 6), (NULL, 7)
statement ok
INSERT INTO integers VALUES (NULL, 6), (NULL, 7)
statement ok
INSERT INTO integers VALUES (NULL, 6), (NULL, 7)
statement ok
INSERT INTO integers VALUES (NULL, 6), (NULL, 7)
statement ok
INSERT INTO integers VALUES (NULL, 6), (NULL, 7)
statement ok
INSERT INTO integers VALUES (NULL, 6), (NULL, 7)
statement ok
INSERT INTO integers VALUES (NULL, 6), (NULL, 7)
statement ok
INSERT INTO integers VALUES (NULL, 6), (NULL, 7)
statement ok
INSERT INTO integers VALUES (NULL, 6), (NULL, 7)
statement error
INSERT INTO integers VALUES (NULL, 6), (3, 7)
----
statement ok
DROP TABLE integers