with_bounds()

A utility function to add bounds to an already-computed CounterSummary. The bounds represent the outer limits of the timestamps allowed for this CounterSummary as well as the edges of the range to extrapolate to in functions that allow it.

with_bounds(
    summary CounterSummary,
    bounds TSTZRANGE,
) RETURNS CounterSummary

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

Required arguments

NameTypeDescription
summaryCounterSummaryThe input CounterSummary
boundsTSTZRANGEA range of timestamptz representing the largest and smallest allowed times in this CounterSummary

Returns

NameTypeDescription
counter_aggCounterSummaryA CounterSummary object that can be passed to accessor functions or other objects in the counter aggregate API

Sample usage

SELECT
    id,
    bucket,
    extrapolated_rate(
        with_bounds(
            summary,
            time_bucket_range('15 min'::interval, bucket)
        )
    )
FROM (
    SELECT
        id,
        time_bucket('15 min'::interval, ts) AS bucket,
        counter_agg(ts, val) AS summary
    FROM foo
    GROUP BY id, time_bucket('15 min'::interval, ts)
) t

Found an issue on this page?

Report an issue!

Related Content