Array functions

**Returned value**

For a single argument returns the number of unique
elements. For multiple arguments returns the number of unique tuples made from
elements at corresponding positions across the arrays.
[`UInt32`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Single argument**

```
SELECT arrayUniq([1, 1, 2, 2])
```

```
2
```

**Multiple argument**

```
SELECT arrayUniq([1, 2, 3, 1], [4, 5, 6, 4])
```

```
3
```

## arrayWithConstant[​](#arrayWithConstant "Direct link to arrayWithConstant")

Introduced in: v20.1.0

Creates an array of length `length` filled with the constant `x`.

**Syntax**

```
arrayWithConstant(N, x)
```

**Arguments**

- `length` — Number of elements in the array. [`(U)Int*`](/docs/sql-reference/data-types/int-uint)
- `x` — The value of the `N` elements in the array, of any type.

**Returned value**

Returns an Array with `N` elements of value `x`. [`Array(T)`](/docs/sql-reference/data-types/array)

**Examples**

**Usage example**

```
SELECT arrayWithConstant(3, 1)
```

```
[1, 1, 1]
```

## arrayZip[​](#arrayZip "Direct link to arrayZip")

Introduced in: v20.1.0

Combines multiple arrays into a single array. The resulting array contains the corresponding elements of the source arrays grouped into tuples in the listed order of arguments.

**Syntax**

```
arrayZip(arr1, arr2, ... , arrN)
```

**Arguments**

- `arr1, arr2, ... , arrN` — N arrays to combine into a single array. [`Array(T)`](/docs/sql-reference/data-types/array)

**Returned value**

Returns an array with elements from the source arrays grouped in tuples. Data types in the tuple are the same as types of the input arrays and in the same order as arrays are passed [`Array(T)`](/docs/sql-reference/data-types/array)

**Examples**

**Usage example**

```
SELECT arrayZip(['a', 'b', 'c'], [5, 2, 1]);
```

```
[('a', 5), ('b', 2), ('c', 1)]
```

## arrayZipUnaligned[​](#arrayZipUnaligned "Direct link to arrayZipUnaligned")

Introduced in: v20.1.0

Combines multiple arrays into a single array, allowing for unaligned arrays (arrays of differing lengths). The resulting array contains the corresponding elements of the source arrays grouped into tuples in the listed order of arguments.

**Syntax**

```
arrayZipUnaligned(arr1, arr2, ..., arrN)
```

**Arguments**

- `arr1, arr2, ..., arrN` — N arrays to combine into a single array. [`Array(T)`](/docs/sql-reference/data-types/array)

**Returned value**

Returns an array with elements from the source arrays grouped in tuples. Data types in the tuple are the same as types of the input arrays and in the same order as arrays are passed. [`Array(T)`](/docs/sql-reference/data-types/array) or [`Tuple(T1, T2, ...)`](/docs/sql-reference/data-types/tuple)

**Examples**

**Usage example**

```
SELECT arrayZipUnaligned(['a'], [1, 2, 3]);
```

```
[('a', 1),(NULL, 2),(NULL, 3)]
```

## countEqual[​](#countEqual "Direct link to countEqual")

Introduced in: v1.1.0

Returns the number of elements in the array equal to `x`. Equivalent to `arrayCount(elem -> elem = x, arr)`.

`NULL` elements are handled as separate values.

**Syntax**

```
countEqual(arr, x)
```

**Arguments**

- `arr` — Array to search. [`Array(T)`](/docs/sql-reference/data-types/array)
- `x` — Value in the array to count. Any type.

**Returned value**

Returns the number of elements in the array equal to `x` [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT countEqual([1, 2, NULL, NULL], NULL)
```

```
2
```

## empty[​](#empty "Direct link to empty")

Introduced in: v1.1.0

Checks whether the input array is empty.

An array is considered empty if it does not contain any elements.

Note

Can be optimized by enabling the [`optimize_functions_to_subcolumns` setting](/docs/operations/settings/settings#optimize_functions_to_subcolumns). With `optimize_functions_to_subcolumns = 1` the function reads only [size0](/docs/sql-reference/data-types/array#array-size) subcolumn instead of reading and processing the whole array column. The query `SELECT empty(arr) FROM TABLE;` transforms to `SELECT arr.size0 = 0 FROM TABLE;`.

The function also works for Strings or UUIDs.

**Syntax**

```
empty(arr)
```

**Arguments**

- `arr` — Input array. [`Array(T)`](/docs/sql-reference/data-types/array)

**Returned value**

Returns `1` for an empty array or `0` for a non-empty array [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT empty([]);
```

```
1
```

## emptyArrayDate[​](#emptyArrayDate "Direct link to emptyArrayDate")

Introduced in: v1.1.0

Returns an empty Date array

**Syntax**

```
emptyArrayDate()
```

**Arguments**

- None.

**Returned value**

An empty Date array. [`Array(T)`](/docs/sql-reference/data-types/array)

**Examples**

**Usage example**

```
SELECT emptyArrayDate
```

```
[]
```

## emptyArrayDateTime[​](#emptyArrayDateTime "Direct link to emptyArrayDateTime")

Introduced in: v1.1.0

Returns an empty DateTime array

**Syntax**

```
emptyArrayDateTime()
```

**Arguments**

- None.

**Returned value**

An empty DateTime array. [`Array(T)`](/docs/sql-reference/data-types/array)

**Examples**

**Usage example**

```
SELECT emptyArrayDateTime
```

```
[]
```

## emptyArrayFloat32[​](#emptyArrayFloat32 "Direct link to emptyArrayFloat32")

Introduced in: v1.1.0

Returns an empty Float32 array

**Syntax**

```
emptyArrayFloat32()
```

**Arguments**

- None.

**Returned value**

An empty Float32 array. [`Array(T)`](/docs/sql-reference/data-types/array)

**Examples**

**Usage example**

```
SELECT emptyArrayFloat32
```

```
[]
```

## emptyArrayFloat64[​](#emptyArrayFloat64 "Direct link to emptyArrayFloat64")

Introduced in: v1.1.0

Returns an empty Float64 array

**Syntax**

```
emptyArrayFloat64()
```

**Arguments**

- None.

**Returned value**

An empty Float64 array. [`Array(T)`](/docs/sql-reference/data-types/array)

**Examples**

**Usage example**

```
SELECT emptyArrayFloat64
```

```
[]
```

## emptyArrayInt16[​](#emptyArrayInt16 "Direct link to emptyArrayInt16")

Introduced in: v1.1.0

Returns an empty Int16 array

**Syntax**

```
emptyArrayInt16()
```

**Arguments**

- None.

**Returned value**

An empty Int16 array. [`Array(T)`](/docs/sql-reference/data-types/array)

**Examples**

**Usage example**

```
SELECT emptyArrayInt16
```

```
[]
```

## emptyArrayInt32[​](#emptyArrayInt32 "Direct link to emptyArrayInt32")

Introduced in: v1.1.0

Returns an empty Int32 array

**Syntax**

```
emptyArrayInt32()
```

**Arguments**

- None.

**Returned value**

An empty Int32 array. [`Array(T)`](/docs/sql-reference/data-types/array)

**Examples**

**Usage example**

```
SELECT emptyArrayInt32
```

```
[]
```

## emptyArrayInt64[​](#emptyArrayInt64 "Direct link to emptyArrayInt64")

Introduced in: v1.1.0

Returns an empty Int64 array

**Syntax**

```
emptyArrayInt64()
```

**Arguments**

- None.

**Returned value**

An empty Int64 array. [`Array(T)`](/docs/sql-reference/data-types/array)

**Examples**

**Usage example**

```
SELECT emptyArrayInt64
```

```
[]
```

## emptyArrayInt8[​](#emptyArrayInt8 "Direct link to emptyArrayInt8")

Introduced in: v1.1.0

Returns an empty Int8 array

**Syntax**

```
emptyArrayInt8()
```

**Arguments**

- None.

**Returned value**

An empty Int8 array. [`Array(T)`](/docs/sql-reference/data-types/array)

**Examples**

**Usage example**

```
SELECT emptyArrayInt8
```

```
[]
```

## emptyArrayString[​](#emptyArrayString "Direct link to emptyArrayString")

Introduced in: v1.1.0

Returns an empty String array

**Syntax**

```
emptyArrayString()
```

**Arguments**

- None.

**Returned value**

An empty String array. [`Array(T)`](/docs/sql-reference/data-types/array)

**Examples**

**Usage example**

```
SELECT emptyArrayString
```

```
[]
```

## emptyArrayToSingle[​](#emptyArrayToSingle "Direct link to emptyArrayToSingle")

Introduced in: v1.1.0

Accepts an empty array and returns a one-element array that is equal to the default value.

**Syntax**

```
emptyArrayToSingle(arr)
```

**Arguments**

- `arr` — An empty array. [`Array(T)`](/docs/sql-reference/data-types/array)

**Returned value**