state_periods()

Returns the times in a given state in a timeline aggregate.

  1. state_periods(
  2. state [TEXT | BIGINT],
  3. agg TimelineAgg
  4. ) 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

NameTypeDescription
stateTEXT or BIGINTThe state to get data for
aggTimelineAggThe aggregate to get data for

Returns

ColumnTypeDescription
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 start_time, end_time FROM toolkit_experimental.state_periods(
  2. 'OK',
  3. (SELECT toolkit_experimental.timeline_agg(ts, state) FROM states_test)
  4. );

Example output:

  1. start_time | end_time
  2. ------------------------+------------------------
  3. 2020-01-01 00:00:11+00 | 2020-01-01 00:01:00+00
  4. 2020-01-01 00:01:03+00 | 2020-01-01 00:02:00+00