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
SELECT ARRAY_AVG(array_col)
-- 3
SELECT ARRAY_AVG(array_col)
-- NULL
SELECT ARRAY_AVG(array_col)
-- NULL
SELECT ARRAY_AVG(array_col)
-- NULL
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.