-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Treat all NULL values differently in UNIQUE indexes
SQL standard can be interpreted differently: either NULL values are all unique (SQLite, PostgreSQL, ... and now Genji) or they are considered equal (SQL Server, ...).
- Loading branch information
Showing
7 changed files
with
87 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- setup: | ||
CREATE TABLE test (a int unique, b int); | ||
|
||
-- test: same value | ||
INSERT INTO test (a, b) VALUES (1, 1); | ||
INSERT INTO test (a, b) VALUES (1, 1); | ||
-- error: | ||
|
||
-- test: same value, same statement | ||
INSERT INTO test (a, b) VALUES (1, 1), (1, 1); | ||
-- error: | ||
|
||
-- test: different values | ||
INSERT INTO test (a, b) VALUES (1, 1), (2, 2); | ||
/* result: | ||
{a: 1, b: 1} | ||
{a: 2, b: 2} | ||
*/ | ||
|
||
-- test: NULL | ||
INSERT INTO test (b) VALUES (1), (2); | ||
INSERT INTO test (a, b) VALUES (NULL, 3); | ||
SELECT a, b FROM test; | ||
/* result: | ||
{a: NULL, b: 1} | ||
{a: NULL, b: 2} | ||
{a: NULL, b: 3} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
-- setup: | ||
CREATE TABLE test (a int, b int, c int, d int, UNIQUE (a, b, c)); | ||
|
||
-- test: same value | ||
INSERT INTO test (a, b, c, d) VALUES (1, 1, 1, 1); | ||
INSERT INTO test (a, b, c, d) VALUES (1, 1, 1, 1); | ||
-- error: | ||
|
||
-- test: same value, same statement | ||
INSERT INTO test (a, b, c, d) VALUES (1, 1, 1, 1), (1, 1, 1, 1); | ||
-- error: | ||
|
||
-- test: different values | ||
INSERT INTO test (a, b, c, d) VALUES (1, 1, 1, 1), (1, 2, 1, 1); | ||
/* result: | ||
{a: 1, b: 1, c: 1, d: 1} | ||
{a: 1, b: 2, c: 1, d: 1} | ||
*/ | ||
|
||
-- test: NULL | ||
INSERT INTO test (d) VALUES (1), (2); | ||
INSERT INTO test (c, d) VALUES (3, 3); | ||
INSERT INTO test (c, d) VALUES (3, 3); | ||
INSERT INTO test (b, c, d) VALUES (4, 4, 4); | ||
INSERT INTO test (b, c, d) VALUES (4, 4, 4); | ||
INSERT INTO test (a, b, c, d) VALUES (5, null, 5, 5); | ||
INSERT INTO test (a, c, d) VALUES (5, 5, 5); | ||
SELECT a, b, c, d FROM test; | ||
/* result: | ||
{a: NULL, b: NULL, c: NULL, d: 1} | ||
{a: NULL, b: NULL, c: NULL, d: 2} | ||
{a: NULL, b: NULL, c: 3, d: 3} | ||
{a: NULL, b: NULL, c: 3, d: 3} | ||
{a: NULL, b: 4, c: 4, d: 4} | ||
{a: NULL, b: 4, c: 4, d: 4} | ||
{a: 5, b: NULL, c: 5, d: 5} | ||
{a: 5, b: NULL, c: 5, d: 5} | ||
*/ |