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.
Reference: Haybarn WASM 2.0.0-rc12
Arguments & returns
list_transform(list, lambda)
Scalar
| Overload link | list | lambda |
Returns |
|---|---|---|---|
| #01 | ANY[] | LAMBDA |
ANY[] |
Transform each item in a list
Apply a lambda expression to every item of a SQL list while retaining the list structure and item order.
A NULL item is passed to the lambda. Arithmetic on that item yields NULL; the item is not automatically removed.
Guide example · Run to view results.
| doubled |
|---|
[2, NULL, 6] |
Watch for: Haybarn 2.0 examples use lambda x: expression. Use list_filter() to remove items, or unnest() to turn the list into rows.
Example
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.
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