SQLite Forum

Unexpected behaviour of the sum function

Unexpected behaviour of the sum function

(1) By anonymous on 2020-09-01 11:50:05 [link] [source]

Due to a bug in our program we discovered an unexpected behaviour of the function sum().
We had the following scenario:

CREATE TABLE "test" ("x"	REAL);
INSERT INTO  test('1,2');
INSERT INTO  test('1,5');

Result: 2.0

I would expect an error message or a warning instead of a result pretending to be valid.

(2) By Richard Hipp (drh) on 2020-09-01 12:08:04 in reply to 1 [source]

SQLite allows you to use a string as a number. It uses whatever prefix of the string that looks like a number. In your case, that prefix is '1'. So the answer of 2.0 is correct.