first_val, last_val
This pair of functions returns the values of the first and last points in a CounterSummary aggregate.
2. first_val(
4. cs CounterSummary
6. ) RETURNS DOUBLE PRECISION
8. last_val(
10. cs CounterSummary
12. ) RETURNS DOUBLE PRECISION
Required arguments
| Name |
Type |
Description |
cs |
CounterSummary |
The input CounterSummary from a previous counter_agg (point form) call, often from a continuous aggregate |
Returns
| Column |
Type |
Description |
first_val |
DOUBLE PRECISION |
The value of the first point in the CounterSummary |
| Column |
Type |
Description |
last_val |
DOUBLE PRECISION |
The value of the last point in the CounterSummary |
Sample usage
This example produces a CounterSummary from timestamps and associated values, then applies the first_val and last_val accessors:
2. WITH t as (
4. SELECT
6. time_bucket('1 day'::interval, ts) as dt,
8. counter_agg(ts, val) AS cs -- get a CounterSummary
10. FROM table
12. GROUP BY time_bucket('1 day'::interval, ts)
14. )
16. SELECT
18. dt,
20. first_val(cs) -- extract the value of the first point in the CounterSummary
22. last_val(cs) -- extract the value of the last point in the CounterSummary
24. FROM t;