The sum() function returns NULL if there are no non-NULL values in the column. Total will return 0 in that case. Note that sqlite3_column_type() inspects the value for the current row, whereas sqlite3_column_decltype() returns the declared type of the table column.