Skip to content

total ​

Calculates an approximate floating-point sum. Unlike sum, it returns 0.0 when no non-NULL value contributes.

text
total(value)

The argument is a numeric expression. NULL values are skipped, and legacy text or blob inputs follow SQL numeric conversion. Native nonnumeric values require an explicit numeric cast.

The result is REAL, including when every input is an integer or decimal. Use sum when the total must remain exact. Nonfinite arithmetic can produce infinity; an indeterminate NaN result becomes SQL NULL.

Empty input

sql
SELECT sum(generate_series), total(generate_series)
FROM generate_series(1, 3)
WHERE generate_series > 10
FORMAT csv;
text
\N,0.0