Skip to main content
Since 1.3.0 Calculate the y intercept from a two-dimensional statistical aggregate. The calculation uses the standard least-squares fitting for linear regression.
intercept(
    summary StatsSummary2D
) RETURNS DOUBLE PRECISION

Arguments

NameTypeDefaultRequiredDescription
summaryStatsSummary2D-The statistical aggregate produced by a stats_agg call

Returns

ColumnTypeDescription
interceptDOUBLE PRECISIONThe y intercept of the least-squares fit line

Samples

Calculate the y intercept from independent variable y and dependent variable x for each 15-minute time bucket:
SELECT
    id,
    time_bucket('15 min'::interval, ts) AS bucket,
    intercept(stats_agg(y, x)) AS summary
FROM foo
GROUP BY id, time_bucket('15 min'::interval, ts)