Skip to main content
Since 1.11.0 Get the value of the last point in a TimeWeightSummary aggregate.

Arguments

NameTypeDefaultRequiredDescription
twsTimeWeightSummary-The input TimeWeightSummary from a time_weight() call

Returns

ColumnTypeDescription
last_valDOUBLE PRECISIONThe value of the last point in the TimeWeightSummary

Samples

Produce a linear TimeWeightSummary over the column val and get the last value:
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_val(tw)
FROM t;