rollup(TimeWeightSummary)

  1. rollup(
  2. tws TimeWeightSummary
  3. ) RETURNS TimeWeightSummary

An aggregate to compute a combined TimeWeightSummary from a series of non-overlapping TimeWeightSummaries. Overlapping TimeWeightSummaries will cause errors. See Notes on Parallelism and Ordering for more information.

Required arguments

NameTypeDescription
twsTimeWeightSummaryThe input TimeWeightSummary from a previous time_weight call, often from a continuous aggregate

Returns

ColumnTypeDescription
time_weightTimeWeightSummaryA TimeWeightSummary object that can be passed to other functions within the time weighting API

Sample usage

  1. WITH t as (
  2. SELECT
  3. date_trunc('day', ts) as dt,
  4. time_weight('Linear', ts, val) AS tw -- get a time weight summary
  5. FROM foo
  6. WHERE measure_id = 10
  7. GROUP BY date_trunc('day', ts)
  8. ), q as (
  9. SELECT rollup(tw) AS full_tw -- do a second level of aggregation to get the full time weighted average
  10. FROM t
  11. )
  12. SELECT
  13. dt,
  14. average(tw), -- extract the average from the time weight summary
  15. average(tw) / (SELECT average(full_tw) FROM q LIMIT 1) as normalized -- get the normalized average
  16. FROM t;