Skip to content

total()

Calculate the exact sum of the values in a `tdigest`

Since 1.21.0

Calculate the exact sum of all the values added to a tdigest aggregate. Unlike percentile calculations, the sum is exact, though there might be some loss of precision. This accessor allows you to calculate the total alongside percentiles, without needing to create two separate aggregates from the same raw data.

Calculate the sum of the integers from 0 to 100.

SELECT total(tdigest(100, data))
FROM generate_series(0, 100) data;
total
-------
5050

The syntax is:

total(
digest TDigest
) RETURNS DOUBLE PRECISION
NameTypeDefaultRequiredDescription
digestTDigest-The tdigest aggregate to extract the sum from
ColumnTypeDescription
totalDOUBLE PRECISIONThe sum of the values in the tdigest.