list_transform()

Returns a list that is the result of applying the lambda function to each element of the input list. See the Lambda Functions section for more details

Arguments & returns

list_transform(list, lambda)

Scalar
Overload link listlambda Returns
#01 ANY[]LAMBDA ANY[]

Example

list_transform example
SQL
Haybarn WASM 1.5.5-rc3 · In your browser

Engine example · Run to view results.

Catalog examples

SELECT
  list_transform([1, 2, 3], x -> x + 1);

In a query

A little function. A whole new list.

Apply the same idea to every value. A lambda lets you describe the transformation right where you use it.

A little function. A whole new list.
SQL
Haybarn WASM 1.5.5-rc3 · In your browser

Guide recipe · Run to view results.

In other engines

Used in larger rewrites 2

These examples use list_transform as one part of a larger SQL translation.

BigQueryarray_to_string()

SELECT ARRAY_TO_STRING(['cake', 'pie', NULL], '--', 'MISSING') AS text
In DuckDB
SELECT ARRAY_TO_STRING(LIST_TRANSFORM(['cake', 'pie', NULL], x -> COALESCE(x, 'MISSING')), '--') AS text

SQLGlot example ↗

Snowflakearray_to_string()

SELECT ARRAY_TO_STRING(x, '')
In DuckDB
SELECT CASE WHEN '' IS NULL THEN NULL ELSE ARRAY_TO_STRING(LIST_TRANSFORM(x, x -> COALESCE(CAST(x AS TEXT), '')), '') END

SQLGlot example ↗