Skip to main content
Since 1.3.0 Calculate the time when the counter value is predicted to have been zero. This is the x-intercept of the linear fit between counter value and time.

Samples

Estimate the time when the counter started
SELECT
    id,
    bucket,
    counter_zero_time(summary)
FROM (
    SELECT
        id,
        time_bucket('15 min'::interval, ts) AS bucket,
        counter_agg(ts, val) AS summary
    FROM foo
    GROUP BY id, time_bucket('15 min'::interval, ts)
) t

Arguments

The syntax is:
counter_zero_time(
    summary CounterSummary
) RETURNS TIMESTAMPTZ
NameTypeDefaultRequiredDescription
summaryCounterSummary-A counter aggregate created using counter_agg

Returns

ColumnTypeDescription
counter_zero_timeTIMESTAMPTZThe time when the counter value is predicted to have been zero