ARRAY_SUM()

All functions > ARRAY > ARRAY_SUM()

Returns the sum of all numeric elements in an array.

Signatures

Returns: The sum of all numeric elements in the array

ARRAY_SUM(array: ARRAY<T>) → T
sql
ParameterTypeRequiredDescription
arrayARRAY<T>YesThe numeric array to sum

Notes

  • Adds all numeric values in the array
  • Ignores NULL values (they do not contribute to the sum)
  • Returns NULL for empty arrays
  • Handles negative values correctly
  • May overflow for very large sums
  • Only works with numeric arrays

See also

Examples

FeatureQL
SELECT
    f1 := ARRAY_SUM(ARRAY[1, 2, 3]), -- Basic sum
    f2 := ARRAY_SUM(ARRAY[1, NULL::BIGINT, 2]), -- NULL elements ignored in sum
    f3 := ARRAY_SUM(ARRAY[]::BIGINT[]) -- Empty array
;
Result
f1 BIGINTf2 BIGINTf3 BIGINT
63null

Last update at: 2026/05/26 17:22:09