Skip to content

total()

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

Since 1.21.0

Calculate the exact sum of all the values added to a uddsketch. 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(uddsketch(100, 0.001, data::double precision))
FROM generate_series(0, 100) data;
total
-------
5050

The syntax is:

total(
sketch UddSketch
) RETURNS DOUBLE PRECISION
NameTypeDefaultRequiredDescription
sketchUddSketch-The uddsketch to extract the sum from
ColumnTypeDescription
totalDOUBLE PRECISIONThe sum of the values in the uddsketch.