num_changes()

The number of times the value changed within the period over which the CounterSummary is calculated. This is determined by evaluating consecutive points. Any change in the value is counted, including counter resets where the counter is reset to zero. This can result in the same adjusted counter value for consecutive points, but is still treated as a change.

  1. num_changes(
  2. summary CounterSummary
  3. ) RETURNS BIGINT

For more information about counter aggregation functions, see the hyperfunctions documentation.

Required arguments

NameTypeDescription
summaryCounterSummaryThe input CounterSummary from a counter_agg call

Returns

NameTypeDescription
num_changesBIGINTThe number of times the value changed

Sample usage

  1. SELECT
  2. id,
  3. bucket,
  4. num_changes(summary)
  5. FROM (
  6. SELECT
  7. id,
  8. time_bucket('15 min'::interval, ts) AS bucket,
  9. counter_agg(ts, val) AS summary
  10. FROM foo
  11. GROUP BY id, time_bucket('15 min'::interval, ts)
  12. ) t