SQLite Forum

Incorrect result caused by SUM function
Login

Incorrect result caused by SUM function

(1) By syang (ysy111) on 2024-03-19 09:28:21 [source]

I think query2 should return Inf just like query1. However, query2 return NULL, it looks like a bug?


CREATE TABLE t0 (c0 DOUBLE );
INSERT INTO t0(c0) VALUES (1),(2),(3);

SELECT SUM(1.7976931348623157E308) as aggr FROM t0; --query1
aggr
Inf
SELECT SUM(1.7976931348623157E308) as aggr FROM t0 where c0 > 1; --query2
aggr
NULL

(2) By Richard Hipp (drh) on 2024-03-19 10:59:05 in reply to 1 [link] [source]

This is due to a corner case in the Kahan-Babushka-Neumaier summation algorithm that was added in version 3.43.0 in order to increase the accuracy of sum() and avg(). The problem should now be fixed on trunk, and on various branches.

Thanks for the bug report.