Last active
February 13, 2020 19:32
-
-
Save TallJimbo/d819876a77cfd79312ad48508cfdd8a2 to your computer and use it in GitHub Desktop.
Reproduces a SQLite 3.31.1 bug in query results with redundant constraints
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
- Result should be "good" only, not "good" and "bad" | |
DROP TABLE IF EXISTS redundant; | |
DROP TABLE IF EXISTS enough; | |
CREATE TABLE redundant ( | |
name VARCHAR(10) PRIMARY KEY | |
); | |
INSERT INTO redundant VALUES('good'); | |
INSERT INTO redundant VALUES('bad'); | |
CREATE TABLE enough ( | |
name VARCHAR(10), | |
FOREIGN KEY(name) REFERENCES redundant (name) | |
); | |
INSERT INTO enough VALUES('good'); | |
INSERT INTO enough VALUES('bad'); | |
SELECT | |
enough.name | |
FROM | |
enough JOIN redundant ON enough.name = redundant.name | |
WHERE | |
enough.name = 'good' -- Remove this line... | |
AND | |
redundant.name = 'good' -- ...or this line (and the AND), it works. | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment