Skip to main content

Categories: Aggregate, Semi-Structured Data

ARRAY_AVG

Returns the average of all non-NULL elements of a list as a DECIMAL value.

Syntax​

ARRAY_AVG(list_column LIST) → DECIMAL​

  • list_column: A numeric array to compute the average of. Every element of the list must be a number such as INT, BIGINT, FLOAT4, FLOAT8, or DECIMAL.

Examples

array_col contains ARRAY[1, 2, 3]
SELECT ARRAY_AVG(array_col)
-- 2
array_col contains ARRAY[2,4,null]
SELECT ARRAY_AVG(array_col)
-- 3
array_col contains ARRAY[]
SELECT ARRAY_AVG(array_col)
-- NULL
array_col contains ARRAY[null]
SELECT ARRAY_AVG(array_col)
-- NULL
array_col contains null
SELECT ARRAY_AVG(array_col)
-- NULL
ARRAY_AVG with an array of decimal values
SELECT ARRAY_AVG(ARRAY[1.0, 2.0, 3.0, 4.0])
-- 2.500000

Usage Notes​

The return type is DECIMAL. If the parameter is NULL, this function returns NULL. If there are no non-null elements in the parameter, this function returns 0.