Array functions

**unicode example**

```
SELECT 'ёлка' AS str1, length(str1), lengthUTF8(str1), normalizeUTF8NFKD(str1) AS str2, length(str2), lengthUTF8(str2)
```

```
┌─str1─┬─length(str1)─┬─lengthUTF8(str1)─┬─str2─┬─length(str2)─┬─lengthUTF8(str2)─┐
│ ёлка │            8 │                4 │ ёлка │           10 │                5 │
└──────┴──────────────┴──────────────────┴──────┴──────────────┴──────────────────┘
```

**ascii\_vs\_utf8 example**

```
SELECT 'ábc' AS str, length(str), lengthUTF8(str)
```

```
┌─str─┬─length(str)──┬─lengthUTF8(str)─┐
│ ábc │            4 │               3 │
└─────┴──────────────┴─────────────────┘
```

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

Introduced in: v1.1.0

Checks whether the input array is non-empty.

An array is considered non-empty if it contains at least one element.

Note

Can be optimized by enabling the [`optimize_functions_to_subcolumns`](/docs/operations/settings/settings#optimize_functions_to_subcolumns) setting. 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 notEmpty(arr) FROM table` transforms to `SELECT arr.size0 != 0 FROM TABLE`.

The function also works for Strings or UUIDs.

**Syntax**

```
notEmpty(arr)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

```
SELECT notEmpty([1,2]);
```

```
1
```

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

Introduced in: v1.1.0

Returns an array of numbers from `start` to `end - 1` by `step`.

The supported types are:

- `UInt8/16/32/64`
- `Int8/16/32/64]`
- All arguments `start`, `end`, `step` must be one of the above supported types. Elements of the returned array will be a super type of the arguments.
- An exception is thrown if the function returns an array with a total length more than the number of elements specified by setting [`function_range_max_elements_in_block`](/docs/operations/settings/settings#function_range_max_elements_in_block).
- Returns `NULL` if any argument has Nullable(nothing) type. An exception is thrown if any argument has `NULL` value (Nullable(T) type).

**Syntax**

```
range([start, ] end [, step])
```

**Arguments**

- `start` — Optional. The first element of the array. Required if `step` is used. Default value: `0`. - `end` — Required. The number before which the array is constructed. - `step` — Optional. Determines the incremental step between each element in the array. Default value: `1`.

**Returned value**

Array of numbers from `start` to `end - 1` by `step`. [`Array(T)`](/docs/sql-reference/data-types/array)

**Examples**

**Usage example**

```
SELECT range(5), range(1, 5), range(1, 5, 2), range(-1, 5, 2);
```

```
┌─range(5)────┬─range(1, 5)─┬─range(1, 5, 2)─┬─range(-1, 5, 2)─┐
│ [0,1,2,3,4] │ [1,2,3,4]   │ [1,3]          │ [-1,1,3]        │
└─────────────┴─────────────┴────────────────┴─────────────────┘
```

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

Introduced in: v1.1.0

Creates an array with a single value.

**Syntax**

```
replicate(x, arr)
```

**Arguments**

- `x` — The value to fill the result array with. [`Any`](/docs/sql-reference/data-types)
- `arr` — An array. [`Array(T)`](/docs/sql-reference/data-types/array)

**Returned value**

Returns an array of the same length as `arr` filled with value `x`. [`Array(T)`](/docs/sql-reference/data-types/array)

**Examples**

**Usage example**

```
SELECT replicate(1, ['a', 'b', 'c']);
```

```
┌─replicate(1, ['a', 'b', 'c'])───┐
│ [1, 1, 1]                       │
└─────────────────────────────────┘
```

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

Introduced in: v1.1.0

Reverses the order of the elements in the input array or the characters in the input string.

**Syntax**

```
reverse(arr | str)
```

**Arguments**

- `arr | str` — The source array or string. [`Array(T)`](/docs/sql-reference/data-types/array) or [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns an array or string with the order of elements or characters reversed.

**Examples**

**Reverse array**

```
SELECT reverse([1, 2, 3, 4]);
```

```
[4, 3, 2, 1]
```

**Reverse string**

```
SELECT reverse('abcd');
```

```
'dcba'
```

## Distance functions[​](#distance-functions "Direct link to Distance functions")

All supported functions are described in [distance functions documentation](/docs/sql-reference/functions/distance-functions).