trim_to()
Reduce the covered interval of a heartbeat aggregate
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.
Samples
Section titled “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 livenessWHERE date > '02-21-2022 UTC' AND date < '3-7-2022 UTC'Arguments
Section titled “Arguments”The syntax is:
trim_to( agg HEARTBEATAGG, start TIMESTAMPTZ, duration INTERVAL) RETURNS HEARTBEATAGG| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| agg | HeartbeatAgg | - | ✔ | A heartbeat aggregate to trim down |
| start | TimestampTz | - | The start of the trimmed range. If not provided, the returned heartbeat aggregate starts from the same time as the starting one | |
| duration | Interval | - | How long the resulting aggregate should cover. If not provided, the returned heartbeat aggregate ends at the same time as the starting one |
Returns
Section titled “Returns”| Column | Type | Description |
|---|---|---|
| trim_to | heartbeat_agg | The trimmed aggregate. |