state_timeline, you can use this function across multiple state aggregates that cover
different 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 state_agg |
| 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 |
|---|---|---|
| state | TEXT | BIGINT | A state found in the state aggregate |
| start_time | TIMESTAMPTZ | The time when the state started (inclusive) |
| end_time | TIMESTAMPTZ | The time when the state ended (exclusive) |
Samples
Given state aggregates bucketed by 1-minute intervals, interpolate the states at the bucket boundaries and get the history of all states. To perform the interpolation, theLAG and LEAD functions are used to get the previous and next state aggregates.