Skip to main content

ARRAY_REDUCE

Introduced or updated: v1.2.762

Reduces a JSON array to a single value by applying a specified Lambda expression. For more information about Lambda expression, see Lambda Expressions.

Syntax

ARRAY_REDUCE(<json_array>, <lambda_expression>)

Examples

This example multiplies all the elements in the array (2 _ 3 _ 4):

SELECT ARRAY_REDUCE(
[2, 3, 4],
(acc, d) -> acc::Int * d::Int
);

-[ RECORD 1 ]-----------------------------------
array_reduce([2, 3, 4], (acc, d) -> acc::Int32 * d::Int32): 24
Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today