last_val()
Get the last value from a counter aggregate
Since 1.11.0
Get the value of the last point from a counter aggregate.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Get the last value from a counter aggregate
WITH t as (
SELECT
time_bucket('1 day'::interval, ts) as dt,
counter_agg(ts, val) AS cs -- get a CounterSummary
FROM table
GROUP BY time_bucket('1 day'::interval, ts)
)
SELECT
dt,
first_val(cs) -- extract the value of the first point in the CounterSummary
last_val(cs) -- extract the value of the last point in the CounterSummary
FROM t;
last_val(
cs CounterSummary
) RETURNS DOUBLE PRECISION
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
cs | CounterSummary | - | ✔ | A counter aggregate produced using counter_agg |
| Column | Type | Description |
|---|---|---|
| last_val | DOUBLE PRECISION | The value of the last point in the counter aggregate |