duration_in, you can use this function across
multiple state aggregates that cover multiple time buckets. Any missing values at the time bucket boundaries are
interpolated from adjacent state aggregates.
Arguments
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| agg | StateAgg | - | ✔ | A state aggregate created with compact_state_agg |
| state | TEXT | BIGINT | - | ✔ | The state to query |
| start | TIMESTAMPTZ | - | ✔ | The start of the interval to be calculated |
| interval | INTERVAL | - | ✔ | The length of the interval to be calculated |
| prev | StateAgg | - | The state aggregate from the prior interval, used to interpolate the value at start. If NULL, the first timestamp in aggregate is used as the start of the interval |
Returns
| Column | Type | Description |
|---|---|---|
| interpolated_duration_in | INTERVAL | The total time spent in the queried state. Displayed as days, hh:mm:ss, or a combination of the two |
Samples
Create a test table that tracks when a system switches betweenstarting, running, and error states. Query the
table for the time spent in the running state. Use LAG and LEAD to get the neighboring aggregates for
interpolation.
If you prefer to see the result in seconds, EXTRACT the epoch from the returned result.