Skip to content

rollup()

Combine multiple state aggregates

Since 1.15.0

Combine multiple state aggregates into a single state aggregate. For example, you can use rollup to combine state aggregates from 15-minute buckets into daily buckets. The aggregates must not overlap: the last timestamp of each one must be at or before the first timestamp of the next, and no two aggregates may start at the same timestamp.

Combine multiple state aggregates and calculate the duration spent in the START state.

WITH buckets AS (SELECT
time_bucket('1 minute', ts) as dt,
state_agg(ts, state) AS sa
FROM states_test
GROUP BY time_bucket('1 minute', ts))
SELECT duration_in(
rollup(buckets.sa),
'START'
)
FROM buckets;

The syntax is:

rollup(
value StateAgg
) RETURNS StateAgg
NameTypeDefaultRequiredDescription
valueStateAgg-✔State aggregates created using state_agg
ColumnTypeDescription
rollupStateAggA new state aggregate that combines the input state aggregates