APPLY_AVG

Returns the average of all elements in a collection (array or set) with numeric values.

Behavior Type

Immutable

Syntax

APPLY_AVG(collection)

Supported Data Types

1D collections of:

  • INTEGER
  • INTERVAL
  • INTERVALYM
  • FLOAT
  • NUMERIC

Null-Handling

The following cases return NULL:

  • if the input collection is NULL
  • if the input collection contains only null values
  • if the input collection is empty

If the input collection contains a mix of null and non-null elements, only the non-null values are considered in the calculation of the average.

Example

=> SELECT apply_avg(ARRAY[1,2.4,5,6]);
apply_avg
-----------
3.6
(1 row)

See also