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

# ARRAY_PREPEND

> Adds an element to the start of an array.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

Returns NULL for a NULL array. A NULL element is inserted as a NULL array element.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
array_prepend(array, element)
```

## Arguments

Type notation used below:

* T is the array element type: BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT.

| Name | Type | Required | Description |
| - | - | - | - |
| array | ARRAY\<T> | Yes | The input array. Nested elements/fields must satisfy the same element-type restrictions. |
| element | T | Yes | The element to add, which may be NULL. Nested elements/fields must satisfy the same element-type restrictions. |

## Returns

* Type: ARRAY\<T>
* Possible values: The input elements plus the added element.
* NULL behavior: Returns NULL for a NULL array. A NULL element is inserted as a NULL array element.
* Shape: The original length plus one.
* Ordering: Original array order with the added element at the start.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Usage notes

* Pass the array first and the element second. An untyped NULL takes the array’s element type. An array of untyped NULLs takes the supplied element’s type.
* INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.

## Examples

### Typical behavior

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT array_prepend(ARRAY[CAST(1 AS INT), CAST(2 AS INT)], CAST(3 AS INT)) AS "value", array_prepend(ARRAY[CAST(1 AS INT), CAST(2 AS INT)], CAST(NULL AS INT)) AS null_element;
```

| value | null\_element |
| - | - |
| \[3,1,2] | \[null,1,2] |

### Prepend a string

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT array_prepend(ARRAY('red', 'blue'), 'green') AS colors;
```

| colors |
| - |
| \["green","red","blue"] |

## Limitations

* The element and the array’s elements must have compatible types. Use explicit casts for mixed numeric types.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.