mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-29 14:04:22 +01:00
# Fix SUM aggregate function for mixed types Fixes #2133 The SUM aggregate function was returning incorrect results when processing tables with mixed numeric and non-numeric values. According to SQLite documentation: > "If any input to sum() is neither an integer nor a NULL, then sum() returns a floating point value" [*](https://sqlite.org/lang_aggfunc.html) Now both SQLite and Turso yield the same output of 44.0. -- I modified `Sum` to increment only for numeric values, skipping non- numeric values. However, if we have mixed numeric values or non-numeric values, we return a float output. Added a flag to keep track of it. as pointed out by @FHaggs , If there are no non-NULL input rows then sum() returns NULL but total() returns 0.0. I decided to include it in this PR as well. Empty was such a natural test case. Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com> Closes #2182
Integration and regression test suite.
# run all tests
cargo test
# run individual test
cargo test test_sequential_write -- --nocapture