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

# Array Functions

## `array_distinct`

Remove duplicate values from the array x.

*Examples:*

```sql examples.sql theme={null}
SELECT array_distinct([1, 2, 3]) as value; -- value '[1, 2, 3]'
SELECT array_distinct([1, 1, 2, 3]) as value; -- value '[1, 2, 3]'
```

*Supported Signatures*

```sql theme={null}
function array_distinct(array<$3>) returns array<$3>
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#array_distinct)

## `array_except`

Returns an array of elements in x but not in y, without duplicates.

*Examples:*

```sql examples.sql theme={null}
SELECT array_except([1, 1, 2, 3], [1]) AS value; -- value '[2, 3]'
```

*Supported Signatures*

```sql theme={null}
function array_except(array<$3>, array<$3>) returns array<$3>
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#array_except)

## `array_intersect`

Returns an array of the elements in the intersection of x and y, without duplicates.

*Examples:*

```sql examples.sql theme={null}
SELECT array_intersect([1, 1, 2, 3], [1]) AS value; -- value '[1]'
SELECT array_intersect(['hello', 'world'], ['hello']) AS value; -- value '[hello]'
```

*Supported Signatures*

```sql theme={null}
function array_intersect(array<$3>, array<$3>) returns array<$3>
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#array_intersect)

## `array_join`

Concatenates the elements of the given array using the delimiter. Null elements are omitted in the result.

*Examples:*

```sql examples.sql theme={null}
SELECT array_join(['hello', 'world'], ' beautiful ') AS value; -- value 'hello beautiful world'
```

*Supported Signatures*

```sql theme={null}
function array_join(array<$1>, varchar) returns varchar
function array_join(array<$1>, varchar, varchar) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#array_join)

## `array_max`

Returns the maximum value of input array.

*Supported Signatures*

```sql theme={null}
function array_max(array<$1>) returns $1
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#array_max)

## `array_min`

Returns the minimum value of input array.

*Supported Signatures*

```sql theme={null}
function array_min(array<$1>) returns $1
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#array_min)

## `array_position`

Returns the position of the first occurrence of the element in array x (or 0 if not found).

*Examples:*

```sql examples.sql theme={null}
SELECT array_position([1, 1, 2], 1) AS value; -- value '1'
```

*Supported Signatures*

```sql theme={null}
function array_position(array<$1>, $1) returns bigint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#array_position)

## `array_remove`

Remove all elements that equal element from array x.

*Examples:*

```sql examples.sql theme={null}
SELECT array_remove([1, 1, 2], 1) AS value; -- value '[2]'
SELECT array_remove(['hello', 'bad', 'world'], 'bad') AS value; -- value '[hello, world]'
```

*Supported Signatures*

```sql theme={null}
function array_remove(array<$3>, $3) returns array<$3>
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#array_remove)

## `array_sort`

Sorts and returns the array x. The elements of x must be orderable. Null elements will be placed at the end of the returned array.

*Supported Signatures*

```sql theme={null}
function array_sort(array<$3>) returns array<$3>
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#array_sort)

## `array_union`

Returns an array of the elements in the union of x and y, without duplicates.

*Examples:*

```sql examples.sql theme={null}
SELECT array_union([1, 1], [2]) as value; -- value '[1, 2]'
```

*Supported Signatures*

```sql theme={null}
function array_union(array<$3>, array<$3>) returns array<$3>
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#array_union)

## `cardinality`

Returns the cardinality (size) of the array x.

*Examples:*

```sql examples.sql theme={null}
SELECT cardinality([1, 1, 2]) as value; -- value '3'
```

*Supported Signatures*

```sql theme={null}
function cardinality(array<$3>) returns bigint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#cardinality)

## `contains`

Takes an array and an element. Returns true if the array contains the element, false if not.

*Examples:*

```sql examples.sql theme={null}
SELECT contains(['hello', 'world'], 'hello') AS value; -- value 'true'
SELECT contains(['hello', 'world'], '😊') AS value; -- value 'false'
```

*Supported Signatures*

```sql theme={null}
function contains(array<$1>, $1) returns boolean
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#contains)

## `element_at`

Returns element of array at given index. If index > 0, this function provides the same functionality as the SQL-standard subscript operator (\[]), except that the function returns NULL when accessing an index larger than array length, whereas the subscript operator would fail in such a case. If index \< 0, element\_at accesses elements from the last to the first.

*Supported Signatures*

```sql theme={null}
function element_at(array<$3>, bigint) returns $3
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#element_at)

## `flatten`

Flattens an array(array(T)) to an array(T) by concatenating the contained arrays.

*Examples:*

```sql examples.sql theme={null}
SELECT flatten(
    ARRAY [ARRAY [1, 2],
    ARRAY [3, 4]])
AS value;
 -- value '[1, 2, 3, 4]'
```

*Supported Signatures*

```sql theme={null}
function flatten(array<array<$3>>) returns array<$3>
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#flatten)

## `repeat`

Repeat element for count times.

*Examples:*

```sql examples.sql theme={null}
select repeat('😉', 4) as value; -- value '😉😉😉😉'
```

*Supported Signatures*

```sql theme={null}
function repeat($1, bigint) returns array<$1>
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/array.html#repeat)
