SQLite User Forum

`((CASE ... END) IS rt1_c0) IS FALSE` flips from `0` to `1` on copied operands
Login

`((CASE ... END) IS rt1_c0) IS FALSE` flips from `0` to `1` on copied operands

(1) By yx (yxchen) on 2026-06-09 03:36:46 [link] [source]

Trigger conditions: v0.c1 is 0, so the CASE expression always reduces to v0.c2 = UPPER(1). Replacing the operands by copied counterparts should preserve the same IS comparison, so the outer ... IS FALSE should remain 0. SQLite instead returns 1.


CREATE VIRTUAL TABLE rt1 USING rtree(c0, c1, c2);
INSERT INTO rt1(c2) VALUES (x'');
CREATE VIEW v0(c0, c1, c2) AS SELECT 1143057507, 0, UPPER(1);

CREATE TABLE TEMP_DATA (
    v0_c0 COLLATE BINARY,
    v0_c1 INTEGER COLLATE BINARY,
    v0_c2 COLLATE BINARY,
    rt1_c0
);
INSERT INTO TEMP_DATA
SELECT v0.c0, v0.c1, v0.c2, rt1.c0
FROM v0, rt1;
CREATE TEMP VIEW VIEW_TEMP AS
SELECT +v0_c0 COLLATE BINARY AS v0_c0,
       v0_c1 AS v0_c1,
       +v0_c2 COLLATE BINARY AS v0_c2,
       +rt1_c0 AS rt1_c0
FROM TEMP_DATA;

SELECT ((CASE WHEN v0_c1 THEN v0_c0 ELSE v0_c2 END) IS (rt1_c0)) IS FALSE
FROM VIEW_TEMP; -- Expected correct result: 0  -- actual Wrong result: 1


(2) By Dan Kennedy (dan) on 2026-06-09 14:48:53 in reply to 1 [source]

Thanks for the report. I think SQLite is getting this one right. The expression in the outer parenthesis does reduce to (v0.c2 = UPPER(1)), but because it comes from the CASE the LHS has no affinity and so the result of that comparison is 0 (lhs is an integer, rhs is text) and so the IS FALSE correctly evaluates to 1.

You're using a fuzzer to find these problems, correct? Assuming so, please post them at:

https://sqlite.org/bugs/

These reports are appreciated by the development team very much, but they tend to clog up the forum for other users.

Dan.