Skip to main content
Since 1.16.0 Reduce the time range covered by a heartbeat aggregate. This can only be used to narrow the covered interval, passing arguments that would extend beyond the range covered by the initial aggregate gives an error.
trim_to(
    agg HEARTBEATAGG,
    start TIMESTAMPTZ,
    duration INTERVAL
) RETURNS HEARTBEATAGG

Arguments

NameTypeDefaultRequiredDescription
aggHeartbeatAgg-A heartbeat aggregate to trim down
startTimestampTz-The start of the trimmed range. If not provided, the returned heartbeat aggregate starts from the same time as the starting one
durationInterval-How long the resulting aggregate should cover. If not provided, the returned heartbeat aggregate ends at the same time as the starting one

Returns

ColumnTypeDescription
trim_toheartbeat_aggThe trimmed aggregate

Samples

Given a table called liveness containing weekly heartbeat aggregates in column health with timestamp column date, use this query to roll up several weeks and trim the result to an exact month:
SELECT trim_to(rollup(health), '03-1-2022 UTC', '1 month')
FROM liveness
WHERE date > '02-21-2022 UTC' AND date < '3-7-2022 UTC'