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
    -- Mean of BIGINT elements
    f1 := ARRAY_AVG(ARRAY(1, 2, 3, 4)),
    -- NULL elements excluded from count and sum
    f2 := ARRAY_AVG(ARRAY(1, NULL::BIGINT, 3))
;
Result
f1 VARCHARf2 VARCHAR
2.52.0

Edge cases

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

Last update at: 2026/06/20 10:08:10