Skip to main content
Lambda expressions are anonymous functions that can be passed as parameters into higher-order SQL functions. Lambda expressions allow you to develop code that is more concise, elegant, and extensible. Lambda expressions are written with the -> operator, which reads “goes to”. The left side of -> is the input parameters (if any) and the right side is an expression. From v2.5 onwards, the database supports using lambda expressions in the following higher-order SQL functions: array_map(), array_filter(), array_sum(), and array_sortby().

Syntax

Parameters

  • parameter: the input parameters for the lambda expression, which can accept zero, one, or more parameters. Two or more input parameters are enclosed in parentheses.
  • expression: a simple expression that references parameter. The expression must be valid for the input parameters.

Return value

The type of the return value is determined by the result type of expression.

Usage notes

Almost all scalar functions can be used in a lambda body. But there are a few exceptions:
  • Subqueries are not supported, for example, x -> 5 + (SELECT 3).
  • Aggregate functions are not supported, for example, x -> min(y).
  • Window functions are not supported.
  • Table functions are not supported.
  • Correlated columns cannot occur in lambda functions.

Examples

Simple examples of lambda expressions:
An example of using lambda expressions in higher-order functions: