Lists & arrays
Scalar
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 | list | lambda |
Returns |
|---|---|---|---|
| #01 | ANY[] | LAMBDA |
ANY[] |
Example
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.
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