first_time, last_time
This pair of functions returns the timestamps of the first and last points in a CounterSummary aggregate.
2. first_time(
4. cs CounterSummary
6. ) RETURNS TIMESTAMPTZ
8. last_time(
10. cs CounterSummary
12. ) RETURNS TIMESTAMPTZ
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_time |
TIMESTAMPTZ |
The time of the first point in the CounterSummary |
| Column |
Type |
Description |
last_time |
TIMESTAMPTZ |
The time of the last point in the CounterSummary |
Sample usage
This example produces a CounterSummary from timestamps and associated values, then applies the first_time and last_time 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_time(cs) -- extract the timestamp of the first point in the CounterSummary
22. last_time(cs) -- extract the timestamp of the last point in the CounterSummary
24. FROM t;