SQLite User Forum

Incorrect query result caused by type conversion
Login

Incorrect query result caused by type conversion

(1) By syang (ysy111) on 2024-03-06 02:50:25 [source]

Description

Since f1=0,the second query should return nothing as the thrid query did.the bug can be reproduced in CLI (https://sqlite.org/fiddle/index.html SQLite version 3.46.0 2024-03-05 )

sqlite> SELECT (c0==CAST(c4 AS REAL)) AS f1 FROM rt1, v0;
0

sqlite> SELECT (c0==CAST(c4 AS REAL)) AS f1 FROM rt1, v0 WHERE f1;
0

sqlite> SELECT f1 FROM (SELECT (c0==CAST(c4 AS REAL)) AS f1, (c0==CAST(c4 AS REAL)) IS TRUE AS flag FROM rt1, v0 WHERE flag=1);  
sqlite> --nothing

How to Repeat

CREATE VIRTUAL TABLE rt1 USING rtree_i32(c0, c1, c2, +c3 INT );
INSERT INTO rt1(c0, c2, c3) VALUES ('9223372036854775807', '1840618558', 0.35548821863495284);
CREATE VIEW v0(c4) AS SELECT CAST(COALESCE(DISTINCT c0,c0) AS BLOB) FROM rt1;

SELECT (c0==CAST(c4 AS REAL)) AS f1 FROM rt1, v0 WHERE f1;
SELECT f1 FROM (SELECT (c0==CAST(c4 AS REAL)) AS f1, (c0==CAST(c4 AS REAL)) IS TRUE AS flag FROM rt1, v0 WHERE flag=1);

(2) By Richard Hipp (drh) on 2024-03-06 11:40:18 in reply to 1 [link] [source]

This is a rounding error when comparing the integer rowid of an RTREE table against a large float-point value. Now fixed at check-in 027e5336.