> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

> Reference material for ARRAY_TRANSFORM function

# ARRAY_TRANSFORM

Returns an array by applying `<function>` on each element of `<array>`.

The Lambda function `<function>` is a mandatory parameter.

**Alias:** `TRANSFORM`

## Syntax

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
ARRAY_TRANSFORM(<function>, <array>)
```

## Parameters

| Parameter    | Description                                                                                                                    | Supported input type |
| :----------- | :----------------------------------------------------------------------------------------------------------------------------- | :------------------- |
| `<function>` | A [Lambda function](/guides/sql-dialect/arrays#manipulating-arrays-with-lambda-functions) 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

<div className="query-window">
  ```
  SELECT ARRAY_TRANSFORM(x -> x * 2, [ 1, 2, 3, 9 ] ) AS levels;
  ```

  | levels <span>array(int)</span> |
  | :----------------------------- |
  | \[2, 4, 6, 18]                 |

  <p><span>Rows: 1</span><span>Execution time: 4.89ms</span></p>
</div>

In the example below, the `TRANSFORM` function is used to [CAST](/reference-sql/functions-reference/conditional-and-miscellaneous/cast) each element from a string to a date type. With each element now as a date type, the [INTERVAL](/reference-sql/lexical-structure/operators#arithmetic-with-date%2Ftime-and-intervals) function is then used to add 5 years to each.

<div className="query-window">
  ```
  SELECT
      ARRAY_TRANSFORM(x -> CAST(x as DATE) + INTERVAL '5 year',
          [ '1979-01-01', '1986-02-26', '1975-04-04' ] )
      AS registeredon;
  ```

  | registeredon <span>array(timestamp)</span>                             |
  | :--------------------------------------------------------------------- |
  | \['1984-01-01 00:00:00', '1991-02-26 00:00:00', '1980-04-04 00:00:00'] |

  <p><span>Rows: 1</span><span>Execution time: 5.62ms</span></p>
</div>

In the example below, `ARRAY_TRANSFORM` is used with `CASE` to modify specific elements based on a condition.

<div className="query-window">
  ```
  SELECT
      ARRAY_TRANSFORM(x, y -> CASE
          WHEN y = 'esimpson' THEN x
          ELSE 0
          END,
          [ 1, 2, 3 ],
          [ 'kennethpark', 'esimpson', 'sabrina21' ] )
      AS levels;
  ```

  | levels <span>array(int)</span> |
  | :----------------------------- |
  | \[0, 2, 0]                     |

  <p><span>Rows: 1</span><span>Execution time: 5.21ms</span></p>
</div>

This example again uses `ARRAY_TRANSFORM` with `CASE`. Elements that don't meet the condition are left unchanged.

<div className="query-window">
  ```
  SELECT
      ARRAY_TRANSFORM(x, y -> CASE
          WHEN y % 2 == 0
          THEN UPPER(x)
          ELSE x END,
          [ 'esimpson', 'sabrina21', 'kennethpark' ],
          [ 1, 2, 3 ] )
      AS players;
  ```

  | players <span>array(text)</span>          |
  | :---------------------------------------- |
  | \['esimpson', 'SABRINA21', 'kennethpark'] |

  <p><span>Rows: 1</span><span>Execution time: 5.32ms</span></p>
</div>

This is another example using `CASE` that changes elements only if they meet the condition.

<div className="query-window">
  ```
  SELECT
      ARRAY_TRANSFORM(x, y -> CASE
          WHEN x < y
          THEN y
          ELSE x END,
          [ 100, 700, 800 ],
          [ 300, 500, 200 ] )
      AS res;
  ```

  | res <span>array(int)</span> |
  | :-------------------------- |
  | \[300, 700, 800]            |

  <p><span>Rows: 1</span><span>Execution time: 5.87ms</span></p>
</div>
