Skip to content

first_time()

Get the first timestamp from a counter aggregate

Since 1.11.0

Get the first timestamp from a counter aggregate.

Get the first and last point of each daily 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_time(cs) -- extract the timestamp of the first point in the CounterSummary
last_time(cs) -- extract the timestamp of the last point in the CounterSummary
FROM t;

The syntax is:

first_time(
cs CounterSummary
) RETURNS TIMESTAMPTZ
NameTypeDefaultRequiredDescription
csCounterSummary-A counter aggregate produced using counter_agg
ColumnTypeDescription
first_timeTIMESTAMPTZThe timestamp of the first point in the counter aggregate