Skip to main content

ARRAY_SUM

Categories: Aggregate, Semi-Structured Data

ARRAY_SUM

Returns the sum of all non-null elements of a list.

Syntax

ARRAY_SUM(list_column LIST) → numeric

  • list_column: Column that contains a LIST expression. Every element of the list must be a number such as INT, BIGINT, FLOAT4, FLOAT8, or DECIMAL. Cannot be an array literal.

Examples

array_col contains ARRAY[1, 2, 3]
SELECT ARRAY_SUM(array_col)
-- 6
array_col contains ARRAY[1,2,null]
SELECT ARRAY_SUM(array_col)
-- 3
array_col contains ARRAY[]
SELECT ARRAY_SUM(array_col)
-- 0
array_col contains ARRAY[null]
SELECT ARRAY_SUM(array_col)
-- 0
array_col contains null
SELECT ARRAY_SUM(array_col)
-- NULL

Usage Notes

The return type is T given an input ARRAY<T>. If the parameter is NULL, this function returns NULL. If there are no non-null elements in the parameter, this function returns 0.