Other functions

Introduced in: v20.10.0

Given a number, this function returns a rounded number with suffix (thousand, million, billion, etc.) as a string.

This function accepts any numeric type as input, but internally it casts them to `Float64`.
Results might be suboptimal with large values.

**Syntax**

```
formatReadableQuantity(x)
```

**Arguments**

- `x` — A number to format. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns a rounded number with suffix as a string. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Format numbers with suffixes**

```
SELECT
    arrayJoin([1024, 1234 * 1000, (4567 * 1000) * 1000, 98765432101234]) AS number,
    formatReadableQuantity(number) AS number_for_humans
```

```
┌─────────number─┬─number_for_humans─┐
│           1024 │ 1.02 thousand     │
│        1234000 │ 1.23 million      │
│     4567000000 │ 4.57 billion      │
│ 98765432101234 │ 98.77 trillion    │
└────────────────┴───────────────────┘
```

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

Introduced in: v1.1.0

Given a size (number of bytes), this function returns a readable, rounded size with suffix (KiB, MiB, etc.) as string.

The opposite operations of this function are [`parseReadableSize`](#parseReadableSize), [`parseReadableSizeOrZero`](#parseReadableSizeOrZero), and [`parseReadableSizeOrNull`](#parseReadableSizeOrNull).
This function accepts any numeric type as input, but internally it casts them to `Float64`. Results might be suboptimal with large values.

**Syntax**

```
formatReadableSize(x)
```

**Aliases**: `FORMAT_BYTES`

**Arguments**

- `x` — Size in bytes. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns a readable, rounded size with suffix as a string. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Format file sizes**

```
SELECT
    arrayJoin([1, 1024, 1024*1024, 192851925]) AS filesize_bytes,
    formatReadableSize(filesize_bytes) AS filesize
```

```
┌─filesize_bytes─┬─filesize───┐
│              1 │ 1.00 B     │
│           1024 │ 1.00 KiB   │
│        1048576 │ 1.00 MiB   │
│      192851925 │ 183.92 MiB │
└────────────────┴────────────┘
```

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

Introduced in: v20.12.0

Given a time interval (delta) in seconds, this function returns a time delta with year/month/day/hour/minute/second/millisecond/microsecond/nanosecond as a string.

This function accepts any numeric type as input, but internally it casts them to `Float64`. Results might be suboptimal with large values.

**Syntax**

```
formatReadableTimeDelta(column[, maximum_unit, minimum_unit])
```

**Arguments**

- `column` — A column with a numeric time delta. [`Float64`](/docs/sql-reference/data-types/float)
- `maximum_unit` — Optional. Maximum unit to show. Acceptable values: `nanoseconds`, `microseconds`, `milliseconds`, `seconds`, `minutes`, `hours`, `days`, `months`, `years`. Default value: `years`. [`const String`](/docs/sql-reference/data-types/string)
- `minimum_unit` — Optional. Minimum unit to show. All smaller units are truncated. Acceptable values: `nanoseconds`, `microseconds`, `milliseconds`, `seconds`, `minutes`, `hours`, `days`, `months`, `years`. If explicitly specified value is bigger than `maximum_unit`, an exception will be thrown. Default value: `seconds` if `maximum_unit` is `seconds` or bigger, `nanoseconds` otherwise. [`const String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a time delta as a string. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT
    arrayJoin([100, 12345, 432546534]) AS elapsed,
    formatReadableTimeDelta(elapsed) AS time_delta
```

```
┌────elapsed─┬─time_delta─────────────────────────────────────────────────────┐
│        100 │ 1 minute and 40 seconds                                        │
│      12345 │ 3 hours, 25 minutes and 45 seconds                             │
│  432546534 │ 13 years, 8 months, 17 days, 7 hours, 48 minutes and 54 seconds│
└────────────┴────────────────────────────────────────────────────────────────┘
```

**With maximum unit**

```
SELECT
    arrayJoin([100, 12345, 432546534]) AS elapsed,
    formatReadableTimeDelta(elapsed, 'minutes') AS time_delta
```

```
┌────elapsed─┬─time_delta─────────────────────────────────────────────────────┐
│        100 │ 1 minute and 40 seconds                                         │
│      12345 │ 205 minutes and 45 seconds                                      │
│  432546534 │ 7209108 minutes and 54 seconds                                  │
└────────────┴─────────────────────────────────────────────────────────────────┘
```

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

Introduced in: v26.2.0

Parses the given query string and applies random AST mutations (fuzzing) to it. Returns the fuzzed query as a string. Non-deterministic: each call may produce a different result. Requires `allow_fuzz_query_functions = 1`.

**Syntax**

```
fuzzQuery(query)
```

**Arguments**

- `query` — The SQL query to be fuzzed. [String](/docs/sql-reference/data-types/string)

**Returned value**

The fuzzed query string [`String`](/docs/sql-reference/data-types/string)

**Examples**

**basic**

```
SET allow_fuzz_query_functions = 1; SELECT fuzzQuery('SELECT 1');
```

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

Introduced in: v23.5.0

Generates random table structure in the format `column1_name column1_type, column2_name column2_type, ...`.

**Syntax**

```
generateRandomStructure([number_of_columns, seed])
```

**Arguments**

- `number_of_columns` — The desired number of columns in the resultant table structure. If set to 0 or `Null`, the number of columns will be random from 1 to 128. Default value: `Null`. [`UInt64`](/docs/sql-reference/data-types/int-uint)
- `seed` — Random seed to produce stable results. If seed is not specified or set to `Null`, it is randomly generated. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Randomly generated table structure. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT generateRandomStructure()
```

```
c1 Decimal32(5), c2 Date, c3 Tuple(LowCardinality(String), Int128, UInt64, UInt16, UInt8, IPv6), c4 Array(UInt128), c5 UInt32, c6 IPv4, c7 Decimal256(64), c8 Decimal128(3), c9 UInt256, c10 UInt64, c11 DateTime
```

**with specified number of columns**

```
SELECT generateRandomStructure(1)
```

```
c1 Map(UInt256, UInt16)
```

**with specified seed**

```
SELECT generateRandomStructure(NULL, 33)
```

```
c1 DateTime, c2 Enum8('c2V0' = 0, 'c2V1' = 1, 'c2V2' = 2, 'c2V3' = 3), c3 LowCardinality(Nullable(FixedString(30))), c4 Int16, c5 Enum8('c5V0' = 0, 'c5V1' = 1, 'c5V2' = 2, 'c5V3' = 3), c6 Nullable(UInt8), c7 String, c8 Nested(e1 IPv4, e2 UInt8, e3 UInt16, e4 UInt16, e5 Int32, e6 Map(Date, Decimal256(70)))
```

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

Introduced in: v25.1.0

Generates and returns sequential numbers starting from the previous counter value.
This function takes a string argument - a series identifier, and an optional starting value.
The server should be configured with Keeper.
The series are stored in Keeper nodes under the path, which can be configured in [`series_keeper_path`](/docs/operations/server-configuration-parameters/settings#series_keeper_path) in the server configuration.

**Syntax**

```
generateSerialID(series_identifier[, start_value])
```

**Arguments**

- `series_identifier` — Series identifier [`const String`](/docs/sql-reference/data-types/string)
- `start_value` — Optional. Starting value for the counter. Defaults to 0. Note: this value is only used when creating a new series and is ignored if the series already exists [`UInt*`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns sequential numbers starting from the previous counter value. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**first call**