Skip to content

state_agg()

Aggregate state data into a state aggregate for further analysis

Since 1.15.0

Aggregate state data into a state aggregate to track state transitions. Unlike compact_state_agg, which only stores durations, state_agg also stores the timestamps of state transitions.

Create a state aggregate to track the status of some devices.

SELECT state_agg(time, status) FROM devices;

The syntax is:

state_agg(
ts TIMESTAMPTZ,
value {TEXT | BIGINT}
) RETURNS StateAgg
NameTypeDefaultRequiredDescription
tsTIMESTAMPTZ-Timestamps associated with each state reading
valueTEXTBIGINT-
ColumnTypeDescription
aggStateAggAn object storing the periods spent in each state, including timestamps of state transitions