weighted_mean
weighted_mean · Weighted average aggregate function for PostgreSQL numeric values.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100041 | weighted_mean | weighted_mean | 1.0.1 | FUNC | PostgreSQL | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
weighted_mean provides a two-argument aggregate over numeric values and weights. It computes the sum of value times weight divided by the sum of weights, returning zero when no rows are processed or the total weight is zero.
The transition function is not declared strict yet dereferences both inputs, so filter NULL values explicitly; malformed NULL calls may crash a backend. Negative weights and a zero total can also make the result misleading. The repository is archived and the aggregate lacks modern parallel-state support; regression-test exact numeric behavior and prefer an explicit maintained SQL expression when practical.