Skip to main content
Since 1.3.0 Calculate the sum of the values contained in a statistical aggregate.
sum(
  summary StatsSummary1D
) RETURNS DOUBLE PRECISION

Arguments

NameTypeDefaultRequiredDescription
summaryStatsSummary1D-The statistical aggregate produced by a stats_agg call

Returns

ColumnTypeDescription
sumDOUBLE PRECISIONThe sum of the values in the statistical aggregate

Samples

Calculate the sum of the integers from 0 to 100:
SELECT sum(stats_agg(data))
  FROM generate_series(0, 100) data;
sum
-----
5050