SQLite User Forum

Unexpected result with expanded tuple comparison
Login

Unexpected result with expanded tuple comparison

(1) By axelteo on 2026-03-20 09:05:21 [source]

Dear SQLite Developers,

I found a test case with an unexpected result on the latest checkout [88a931ea2ae734478928c2a6021b00b0f2be4903]. Query 2 is the lexicographical expansion of the tuple comparison in query 1. However, the queries have different outputs.

CREATE TABLE t0 (c0);
INSERT INTO t0 VALUES ('True');

CREATE TABLE t1 (c0 COLLATE NOCASE, c1 PRIMARY KEY) WITHOUT ROWID;
INSERT INTO t1 VALUES ('a', 1);
INSERT INTO t1 VALUES ('a', 'True');

Query 1: Tuple comparison

SELECT *
FROM t0, t1
WHERE (t1.c1, t1.c0) <= (t0.c0, t0.c0);
-- outputs 1 row

Query 2: Lexicographical Expansion

SELECT *
FROM t0, t1
WHERE t1.c1 < t0.c0 OR (t1.c1 = t0.c0 AND t1.c0 <= t0.c0);
-- outputs 2 rows

Thank you for your efforts in bug fixing and analysis.

(2) By Dan Kennedy (dan) on 2026-03-20 11:37:20 in reply to 1 [link] [source]

Thanks for tracking this down and posting. Should now be fixed here:

https://sqlite.org/src/info/078b3162d0

Dan.