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

# array_position

> Obtains the position of an element in an array.

Obtains the position of an element in an array.

## Syntax

```Haskell theme={null}
array_position(any_array, any_element)
```

## Parameters

* `any_array`: the array to be searched.
* `any_element`: an expression that matches the element in an array.

## Return value

Returns the position of the specified element if the element can be found in the specified array and returns 0 if the element cannot be found in the array.

## Examples

* Example 1: Obtain the position of an element in an array.

```plaintext theme={null}
mysql> select array_position(["apple","orange","pear"], "orange");

+-----------------------------------------------------+

| array_position(['apple','orange','pear'], 'orange') |

+-----------------------------------------------------+

|                                                   2 |

+-----------------------------------------------------+

1 row in set (0.01 sec)
```

* Example 2: Obtain the position of `NULL` in an array.

```sql theme={null}
mysql> select array_position([1, NULL], NULL);
```

```plaintext theme={null}
+--------------------------------+

| array_position([1,NULL], NULL) |

+--------------------------------+

|                              2 |

+--------------------------------+

1 row in set (0.00 sec)
```

* Example 3: Obtain the position of a sub-array in a multi-dimensional array. A position can be returned only when a sub-array that consists of the same elements in the same order as the specified sub-array can be found in the multi-dimensional array.

```Lua theme={null}
mysql> select array_position([[1,2,3], [4,5,6]], [4,5,6]);

+--------------------------------------------+

| array_position([[1,2,3],[4,5,6]], [4,5,6]) |

+--------------------------------------------+

|                                          2 |

+--------------------------------------------+

1 row in set (0.00 sec)



mysql> select array_position([[1,2,3], [4,5,6]], [4,6,5]);

+--------------------------------------------+

| array_position([[1,2,3],[4,5,6]], [4,6,5]) |

+--------------------------------------------+

|                                          0 |

+--------------------------------------------+

1 row in set (0.00 sec)
```

## Keywords

ARRAY\_POSITION, ARRAY


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