Categories:

Semi-structured and structured data functions (Array/Object)

ARRAY_REMOVE_ATÂ¶

Given a source ARRAY, returns an ARRAY with the element at the specified position removed.

For example, `ARRAY_REMOVE_AT([2, 5, 7], 0)` returns an ARRAY with the element at position 0 removed (`[5, 7]`).

SyntaxÂ¶

```ARRAY_REMOVE_AT( <array> , <position> )
```

ArgumentsÂ¶

`array`

The source array.

`position`

The (zero-based) position of the element to be removed. The function removes the element at this position.

A negative position is interpreted as an index from the back of the array (e.g. `-1` removes the last element in the array).

ReturnsÂ¶

An ARRAY with the element at the specified position removed.

If `position` is NULL, the function returns NULL.

Usage notesÂ¶

• If the absolute value of `position` exceeds the length of `array`, the function returns `array` without any elements removed.

ExamplesÂ¶

The following example returns an ARRAY with elements with the first element removed.

```SELECT ARRAY_REMOVE_AT(
[2, 5, 7],
0);
```
```+-------------------------------+
| ARRAY_REMOVE_AT([2, 5, 7], 0) |
|-------------------------------|
| [                             |
|   5,                          |
|   7                           |
| ]                             |
+-------------------------------+
```

The following example returns an ARRAY with elements with the last element removed.

```SELECT ARRAY_REMOVE_AT(
[2, 5, 7],
-1);
```
```+--------------------------------+
| ARRAY_REMOVE_AT([2, 5, 7], -1) |
|--------------------------------|
| [                              |
|   2,                           |
|   5                            |
| ]                              |
+--------------------------------+
```

In the following example, `position` is greater than the length of the ARRAY, so the function returns the ARRAY without making any changes.

```SELECT ARRAY_REMOVE_AT(
[2, 5, 7],
10);
```
```+------------------+
| ARRAY_REMOVE_AT( |
|   [2, 5, 7],     |
|   10)            |
|------------------|
| [                |
|   2,             |
|   5,             |
|   7              |
| ]                |
+------------------+
```
Language: English