Skip to main content
array_map() is a higher-order SQL function that can take lambda functions as arguments.It applies the lambda function to the input arrays and returns a new array. array_map() can accept multiple arrays and can be nested with lambda functions to capture a variable. For more information about lambda functions, see Lambda expression. This function is supported from v2.5. The alias is transform().

Syntax

Usage notes

  • Lambda functions can only be used as the first or last parameter of a higher-order function. Either position does not affect the calculation.
  • The number of arrays must be the same as the input parameters in the lambda function. Otherwise, an error is returned.
  • All the arrays must have the same number of elements. Otherwise, an error is returned.

Examples

Example 1: Increment every element of the array by 100.
Example 2: Sum array1 [1,2,3] and array2 [11,12,13] element by element.
Example 3: Determine whether the element in x is greater than 1.5. If yes, log(x) is returned for the element. If not, (x+y) is returned for the corresponding element.
Example 4: Use array_map() to capture variables. The returned element whose value is 1 indicates the condition is met.
Example 5: Use nested lambda functions.
Example 6: An error is returned because the numbers of arrays and lambda parameters are inconsistent. The lambda function requires only one array but two arrays are passed in.