state_periods()
Returns the times in a given state in a timeline aggregate.
2. state_periods(
4. state [TEXT | BIGINT],
6. agg TimelineAgg
8. ) RETURNS (TIMESTAMPTZ, TIMESTAMPTZ)
warning
Experimental features could have bugs. They might not be backwards compatible, and could be removed in future releases. Use these features at your own risk, and do not use any experimental features in production.
Required arguments
| Name | Type | Description |
|---|---|---|
state |
TEXT or BIGINT |
The state to get data for |
agg |
TimelineAgg |
The aggregate to get data for |
Returns
| Column | Type | Description |
|---|---|---|
start_time |
TIMESTAMPTZ |
The time the state started at (inclusive) |
end_time |
TIMESTAMPTZ |
The time the state ended at (exclusive) |
Sample usage
Getting the history of states in a timeline aggregate:
2. SELECT start_time, end_time FROM toolkit_experimental.state_periods(
4. 'OK',
6. (SELECT toolkit_experimental.timeline_agg(ts, state) FROM states_test)
8. );
Example output:
2. start_time | end_time
4. ------------------------+------------------------
6. 2020-01-01 00:00:11+00 | 2020-01-01 00:01:00+00
8. 2020-01-01 00:01:03+00 | 2020-01-01 00:02:00+00
