Skip to content

Instantly share code, notes, and snippets.

@TallJimbo
Last active February 13, 2020 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TallJimbo/d819876a77cfd79312ad48508cfdd8a2 to your computer and use it in GitHub Desktop.
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
- 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