<function> on each element of <array>.
The Lambda function <function> is a mandatory parameter.
Alias: TRANSFORM
Syntax
Parameters
| Parameter | Description | Supported input type |
|---|---|---|
<function> | A Lambda function used to check elements in the array. | Any Lambda function |
<array> | The array to be transformed by the function. | Any array |
Return Type
ARRAY having the return type of <function> as its element type
Examples
[2, 4, 6, 18]
In the example below, the TRANSFORM function is used to CAST each element from a string to a date type. With each element now as a date type, the INTERVAL function is then used to add 5 years to each.
['1984-01-01 00:00:00'::TIMESTAMP, '1991-02-26 00:00:00'::TIMESTAMP, '1980-04-04 00:00:00'::TIMESTAMP]
In the example below, ARRAY_TRANSFORM is used with CASE to modify specific elements based on a condition.
[0, 2, 0]
This example again uses ARRAY_TRANSFORM with CASE. Elements that don’t meet the condition are left unchanged.
['esimpson', 'SABRINA21', 'kennethpark']
This is another example using CASE that changes elements only if they meet the condition.
[300, 700, 800]