ARRAY_AVG()

All functions > ARRAY > ARRAY_AVG()

Returns the arithmetic mean (average) of all numeric elements in an array.

Signatures

Returns: The arithmetic mean as a DOUBLE value

ARRAY_AVG(array: ARRAY<T>) → DOUBLE
sql
ParameterTypeRequiredDescription
arrayARRAY<T>YesThe numeric array to calculate the average of

Notes

  • Calculates sum divided by count of non-NULL values
  • Ignores NULL values in the calculation
  • Always returns DOUBLE regardless of input type
  • Returns NULL for empty arrays or arrays with only NULL values
  • Uses floating-point arithmetic for precision

See also

Examples

Typical averages

FeatureQL
SELECT
    f1 := ARRAY_AVG(ARRAY[1, 2, 3, 4]), -- Mean of BIGINT elements
    f2 := ARRAY_AVG(ARRAY[1, NULL::BIGINT, 3]) -- NULL elements excluded from count and sum
;
Result
f1 VARCHARf2 VARCHAR
2.52.0

Edge cases

FeatureQL
SELECT
    f1 := ARRAY_AVG(ARRAY[]::BIGINT[]) -- Empty array → NULL
;
Result
f1 VARCHAR
NULL

Last update at: 2026/05/26 17:22:09