---
schema_version: "1"
id: ebbb418c67d608e9aa17eacd86bd058ca55e348c9b61fea4c724680bc5c92abb
title: Lambda Expressions
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-query-guide/references/data-cloud-sql-reference/lambda-expressions.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/lambda-expressions.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: d8d7a8d776d2cf3e601b701201eca0a1e7ea9ecc227be2800129affe6dd7dd50
products:
  - Data 360 Query Guide
  - Data 360 Developer Documentation
---
# Lambda Expressions

**Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

Lambda expressions are anonymous functions you pass as arguments to higher-order functions such as `ARRAY_TRANSFORM` and `ARRAY_FILTER`. They enable element-wise operations on arrays without writing separate function definitions.

## Syntax

```sql
lambda <param1>[, <param2>, ...]: <expression>
```

## Arguments

- `<param1>, <param2>, ...`: One or more parameter names that represent the elements from the input arrays. The number of parameters must match the number of array arguments passed to the function.
- `<expression>`: Any valid SQL expression that uses the parameters. The expression is evaluated once for each element (or tuple of elements) in the input arrays.

## Considerations

- Lambda expressions can only be used as arguments to functions that accept them, such as `ARRAY_TRANSFORM` and `ARRAY_FILTER`.
- The parameter names are local to the lambda and don't conflict with column names in the outer query.
- Lambda expressions can't reference columns or variables from the outer query scope.
- The return type of the lambda expression is inferred from the expression. If the expression returns only NULL, you must cast it to a specific type.
- Data 360 uses the Python / DuckDB-style lambda syntax (`lambda x: expr`), not the Spark / Snowflake-style arrow syntax (`x -> expr`).

## Examples

### Single Parameter Lambda

Use a single parameter when operating on one array.

```sql
SELECT array_transform(ARRAY[1, 2, 3], lambda x: x * 2) AS doubled;
```

Returns `[2, 4, 6]`.

### Multiple Parameter Lambda

Use multiple parameters when operating on multiple arrays in parallel.

```sql
SELECT array_transform(ARRAY[1, 2, 3], ARRAY[10, 20, 30], lambda x, y: x + y) AS sums;
```

Returns `[11, 22, 33]`.

### Lambda with Conditional Logic

Use CASE expressions within lambdas for conditional transformations.

```sql
SELECT array_transform(ARRAY[1, 5, 3], ARRAY[4, 2, 6], lambda x, y:
  CASE WHEN x > y THEN x ELSE y END
) AS maximums;
```

Returns `[4, 5, 6]`.

### Lambda for Filtering

Return a boolean expression to filter array elements.

```sql
SELECT array_filter(ARRAY[1, 2, 3, 4, 5, 6], lambda x: x % 2 = 0) AS evens;
```

Returns `[2, 4, 6]`.

### Lambda with String Operations

Lambdas work with any data type.

```sql
SELECT array_transform(
  ARRAY['hello', 'world'],
  ARRAY['!', '?'],
  lambda x, y: upper(x) || y
) AS result;
```

Returns `["HELLO!", "WORLD?"]`.

## Related Documentation

- [ARRAY_TRANSFORM](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/scalar-func/array-func/array-transform.md)
- [ARRAY_FILTER](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/scalar-func/array-func/array-filter.md)
- [Array Data Type](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/datatype/array.md)
