Lists & arrays
Scalar
list_transform()
Returns a list that is the result of applying the lambda function to each element of the input list. The return type is defined by the return type of the lambda function.
Arguments & returns
list_transform(list, lambda(x))
Scalar
| Overload link | list | lambda(x) |
Returns |
|---|---|---|---|
| #01 | ANY[] | LAMBDA |
ANY[] |
Example
Haybarn WASM 1.5.5-rc3 · In your browser
Engine example · Run to view results.
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.
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
SELECT ARRAY_TO_STRING(LIST_TRANSFORM(['cake', 'pie', NULL], x -> COALESCE(x, 'MISSING')), '--') AS text
Snowflakearray_to_string()
SELECT ARRAY_TO_STRING(x, '')
SELECT CASE WHEN '' IS NULL THEN NULL ELSE ARRAY_TO_STRING(LIST_TRANSFORM(x, x -> COALESCE(CAST(x AS TEXT), '')), '') END