state_timeline()

Returns the timeline of states in a timeline aggregate.

2. state_timeline(

4. agg TimelineAgg

6. ) RETURNS (TEXT, TIMESTAMPTZ, TIMESTAMPTZ)

8. state_int_timeline(

10. agg TimelineAgg

12. ) RETURNS (BIGINT, 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
agg TimelineAgg The aggregate to get data for

Returns

Column Type Description
state TEXT or BIGINT A state found in the TimelineAgg
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 state, start_time, end_time FROM toolkit_experimental.state_timeline(

4. (SELECT toolkit_experimental.timeline_agg(ts, state) FROM states_test));

Example output:

2. state |       start_time       |        end_time

4. -------+------------------------+------------------------

6. START | 2020-01-01 00:00:00+00 | 2020-01-01 00:00:11+00

8. OK    | 2020-01-01 00:00:11+00 | 2020-01-01 00:01:00+00

10. ERROR | 2020-01-01 00:01:00+00 | 2020-01-01 00:01:03+00

12. OK    | 2020-01-01 00:01:03+00 | 2020-01-01 00:02:00+00

14. STOP  | 2020-01-01 00:02:00+00 | 2020-01-01 00:02:00+00