Skip to content

last_time()

Get the last timestamp from a TimeWeightSummary aggregate

Since 1.11.0

Get the timestamp of the last point in a TimeWeightSummary aggregate.

Produce a linear TimeWeightSummary over the column val and get the last timestamp:

WITH t as (
SELECT
time_bucket('1 day'::interval, ts) as dt,
time_weight('Linear', ts, val) AS tw
FROM table
GROUP BY time_bucket('1 day'::interval, ts)
)
SELECT
dt,
last_time(tw)
FROM t;

The syntax is:

last_time(
tw TimeWeightSummary
) RETURNS TIMESTAMPTZ
NameTypeDefaultRequiredDescription
twsTimeWeightSummary-The input TimeWeightSummary from a time_weight() call
ColumnTypeDescription
last_timeTIMESTAMPTZThe time of the last point in the TimeWeightSummary