Skip to content

with_bounds()

Add bounds to a gauge aggregate

Early access 1.6.0

Add time bounds to an already-computed gauge aggregate. Bounds are necessary to use extrapolation accessors on the aggregate.

Create a gauge aggregate for each id and each 15-minute interval. Then add bounds to the gauge aggregate, so you can calculate the extrapolated rate.

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,
gauge_agg(ts, val) AS summary
FROM foo
GROUP BY id, time_bucket('15 min'::interval, ts)
) t

The syntax is:

with_bounds(
summary GaugeSummary,
bounds TSTZRANGE,
) RETURNS GaugeSummary
NameTypeDefaultRequiredDescription
summaryGaugeSummary-A gauge aggregate created using gauge_agg
boundsTSTZRANGE-A range of timestamptz giving the smallest and largest allowed times in the gauge aggregate
ColumnTypeDescription
with_boundsGaugeSummaryA new gauge aggregate with the bounds applied