state_timeline()

Returns the timeline of states in a timeline aggregate.

  1. state_timeline(
  2. agg TimelineAgg
  3. ) RETURNS (TEXT, TIMESTAMPTZ, TIMESTAMPTZ)
  4. state_int_timeline(
  5. agg TimelineAgg
  6. ) 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

NameTypeDescription
aggTimelineAggThe aggregate to get data for

Returns

ColumnTypeDescription
stateTEXT or BIGINTA state found in the TimelineAgg
start_timeTIMESTAMPTZThe time the state started at (inclusive)
end_timeTIMESTAMPTZThe time the state ended at (exclusive)

Sample usage

Getting the history of states in a timeline aggregate:

  1. SELECT state, start_time, end_time FROM toolkit_experimental.state_timeline(
  2. (SELECT toolkit_experimental.timeline_agg(ts, state) FROM states_test));

Example output:

  1. state | start_time | end_time
  2. -------+------------------------+------------------------
  3. START | 2020-01-01 00:00:00+00 | 2020-01-01 00:00:11+00
  4. OK | 2020-01-01 00:00:11+00 | 2020-01-01 00:01:00+00
  5. ERROR | 2020-01-01 00:01:00+00 | 2020-01-01 00:01:03+00
  6. OK | 2020-01-01 00:01:03+00 | 2020-01-01 00:02:00+00
  7. STOP | 2020-01-01 00:02:00+00 | 2020-01-01 00:02:00+00