Skip to content

counter_agg()

Aggregate counter data into an intermediate form for further analysis

Since 1.3.0

This is the first step for performing any aggregate calculations on counter data. Use counter_agg to create an intermediate aggregate from your data. This intermediate form can then be used by one or more accessors in this group to compute final results. Optionally, you can combine multiple intermediate aggregate objects using rollup() before an accessor is applied.

Create a counter aggregate to summarize daily counter data.

SELECT
time_bucket('1 day'::interval, ts) as dt,
counter_agg(ts, val) AS cs
FROM foo
WHERE id = 'bar'
GROUP BY time_bucket('1 day'::interval, ts)

The syntax is:

counter_agg(
ts TIMESTAMPTZ,
value DOUBLE PRECISION
[, bounds TSTZRANGE]
) RETURNS CounterSummary
NameTypeDefaultRequiredDescription
tsTIMESTAMPTZ-The time at each point
valueDOUBLE PRECISION-The value of the counter at each point
boundsTSTZRANGE-The smallest and largest possible times that can be input to this aggregate. Bounds are required for extrapolation, but not for other accessor functions. If you don’t specify bounds at aggregate creation time, you can add them later using the with_bounds function.
ColumnTypeDescription
counter_aggCounterSummaryThe counter aggregate, containing data about the variables in an intermediate form. Pass the aggregate to accessor functions in the counter aggregates API to perform final calculations. Or, pass the aggregate to rollup functions to combine multiple counter aggregates into larger aggregates.