VeloDB Cloud
SQL Reference
SQL Functions
Scalar Functions
Array Functions
ARRAY_SUM

ARRAY_SUM

Description

Calculates the sum of all elements in an array

Syntax

ARRAY_SUM(<src>)

Parameters

ParameterDescription
<src>Corresponding array

Return Value

Returns the sum of all elements in the array. NULL values in the array will be skipped. For an empty array or an array with all NULL values, the result returns a NULL value.

Example

SELECT ARRAY_SUM([1, 2, 3, 6]),ARRAY_SUM([1, 4, 3, 5, NULL]),ARRAY_SUM([NULL]);
+-------------------------+-------------------------------+-------------------------------------------+
| array_sum([1, 2, 3, 6]) | array_sum([1, 4, 3, 5, NULL]) | array_sum(cast([NULL] as ARRAY<BOOLEAN>)) |
+-------------------------+-------------------------------+-------------------------------------------+
|                      12 |                            13 |                                      NULL |
+-------------------------+-------------------------------+-------------------------------------------+