This documentation is related to an older version of Firebolt. For the most current documentation, see Firebolt documentation.
ARRAY_SUM
Returns the sum of elements of <array>
. If the argument <function>
is provided, the values of the array elements are converted by this function before summing.
Syntax
ARRAY_SUM([<function>,] <array>)
Parameters
Parameter | Description | Supported input types |
---|---|---|
<function> | A Lambda function with an arithmetic function used to modify the array elements. | Any function |
<array> | The array to be used to calculate the function. | Any array of numeric types |
Return Type
DOUBLE PRECISION
Example
This example below uses a function to first add 1 to all elements before calculating the sum:
SELECT
ARRAY_SUM(x -> x + 1, [ 4, 1, 3, 2 ]) AS levels;
Returns: 14
In this example below, no function to change the array elements is given.
SELECT
ARRAY_SUM([ 4, 1, 3, 2 ]) AS levels;
Returns: 10