Other functions

For security reasons, the function can only be executed in the default user profile (with `allow_sleep` enabled).

**Syntax**

```
sleep(seconds)
```

**Arguments**

- `seconds` — The number of seconds to pause the query execution to a maximum of 3 seconds. It can be a floating-point value to specify fractional seconds. [`const UInt*`](/docs/sql-reference/data-types/int-uint) or [`const Float*`](/docs/sql-reference/data-types/float)

**Returned value**

Returns `0`. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
-- This query will pause for 2 seconds before completing.
-- During this time, no results will be returned, and the query will appear to be hanging or unresponsive.
SELECT sleep(2);
```

```
┌─sleep(2)─┐
│        0 │
└──────────┘
1 row in set. Elapsed: 2.012 sec.
```

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

Introduced in: v1.1.0

Pauses the execution of a query for a specified number of seconds for each row in the result set.

The `sleepEachRow()` function is primarily used for testing and debugging purposes, similar to the [`sleep()`](#sleep) function.
It allows you to simulate delays or introduce pauses in the processing of each row, which can be useful in scenarios such as:

1. **Testing**: When testing or benchmarking ClickHouse's performance under specific conditions, you can use `sleepEachRow()` to simulate delays or introduce pauses for each row processed.
2. **Debugging**: If you need to examine the state of the system or the execution of a query for each row processed, you can use `sleepEachRow()` to introduce pauses, allowing you to inspect or collect relevant information.
3. **Simulation**: In some cases, you may want to simulate real-world scenarios where delays or pauses occur for each row processed, such as when dealing with external systems or network latencies.

Note

Like the `sleep()` function, it's important to use `sleepEachRow()` judiciously and only when necessary, as it can significantly impact the overall performance and responsiveness of your ClickHouse system, especially when dealing with large result sets.

**Syntax**

```
sleepEachRow(seconds)
```

**Arguments**

- `seconds` — The number of seconds to pause the query execution for each row in the result set to a maximum of 3 seconds. It can be a floating-point value to specify fractional seconds. [`const UInt*`](/docs/sql-reference/data-types/int-uint) or [`const Float*`](/docs/sql-reference/data-types/float)

**Returned value**

Returns `0` for each row. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
-- The output will be delayed, with a 0.5-second pause between each row.
SELECT number, sleepEachRow(0.5) FROM system.numbers LIMIT 5;
```

```
┌─number─┬─sleepEachRow(0.5)─┐
│      0 │                 0 │
│      1 │                 0 │
│      2 │                 0 │
│      3 │                 0 │
│      4 │                 0 │
└────────┴───────────────────┘
```

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

Introduced in: v23.8.0

Function that converts ClickHouse table structure to CapnProto format schema

**Syntax**

```
structureToCapnProtoSchema(table_structure, message)
```

**Arguments**

- None.

**Returned value**

**Examples**

**random**

```
SELECT structureToCapnProtoSchema('s String, x UInt32', 'MessageName') format TSVRaw
```

```
struct MessageName
{
    s @0 : Data;
    x @1 : UInt32;
}
```

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

Introduced in: v23.8.0

Converts a ClickHouse table structure to Protobuf format schema.

This function takes a ClickHouse table structure definition and converts it into a Protocol Buffers (Protobuf)
schema definition in proto3 syntax. This is useful for generating Protobuf schemas that match your ClickHouse
table structures for data interchange.

**Syntax**

```
structureToProtobufSchema(structure, message_name)
```

**Arguments**

- `structure` — ClickHouse table structure definition as a string (e.g., 'column1 Type1, column2 Type2'). [`String`](/docs/sql-reference/data-types/string)
- `message_name` — Name for the Protobuf message type in the generated schema. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a Protobuf schema definition in proto3 syntax that corresponds to the input ClickHouse structure. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Converting ClickHouse structure to Protobuf schema**

```
SELECT structureToProtobufSchema('s String, x UInt32', 'MessageName') FORMAT TSVRaw;
```

```
syntax = "proto3";

message MessageName
{
    bytes s = 1;
    uint32 x = 2;
}
```

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

Introduced in: v20.12.0

Returns the [native interface](/docs/interfaces/tcp) TCP port number listened to by the server.
If executed in the context of a distributed table, this function generates a normal column with values relevant to each shard.
Otherwise it produces a constant value.

**Syntax**

```
tcpPort()
```

**Arguments**

- None.

**Returned value**

Returns the TCP port number. [`UInt16`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT tcpPort()
```

```
┌─tcpPort()─┐
│      9000 │
└───────────┘
```

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

Introduced in: v1.1.0

Throw an exception if argument x is true.
To use the `error_code` argument, configuration parameter `allow_custom_error_code_in_throw` must be enabled.

**Syntax**

```
throwIf(x[, message[, error_code]])
```

**Arguments**

- `x` — The condition to check. [`Any`](/docs/sql-reference/data-types)
- `message` — Optional. Custom error message. [`const String`](/docs/sql-reference/data-types/string)
- `error_code` — Optional. Custom error code. [`const Int8/16/32`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns `0` if the condition is false, throws an exception if the condition is true. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT throwIf(number = 3, 'Too many') FROM numbers(10);
```

```
↙ Progress: 0.00 rows, 0.00 B (0.00 rows/s., 0.00 B/s.) Received exception from server (version 19.14.1):
Code: 395. DB::Exception: Received from localhost:9000. DB::Exception: Too many.
```

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

Introduced in: v1.1.0

Returns the internal name of the data type of the given value.
Unlike function [`toTypeName`](#toTypeName), the returned data type potentially includes internal wrapper columns like `Const` and `LowCardinality`.

**Syntax**

```
toColumnTypeName(value)
```

**Arguments**

- `value` — Value for which to return the internal data type. [`Any`](/docs/sql-reference/data-types)

**Returned value**

Returns the internal data type used to represent the value. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT toColumnTypeName(CAST('2025-01-01 01:02:03' AS DateTime));
```

```
┌─toColumnTypeName(CAST('2025-01-01 01:02:03', 'DateTime'))─┐
│ Const(UInt32)                                             │
└───────────────────────────────────────────────────────────┘
```

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

Introduced in: v1.1.0

Returns the type name of the passed argument.
If `NULL` is passed, the function returns type `Nullable(Nothing)`, which corresponds to ClickHouse's internal `NULL` representation.

**Syntax**

```
toTypeName(x)
```

**Arguments**

- `x` — A value of arbitrary type. [`Any`](/docs/sql-reference/data-types)

**Returned value**

Returns the data type name of the input value. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT toTypeName(123)
```

```
┌─toTypeName(123)─┐
│ UInt8           │
└─────────────────┘
```

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

Introduced in: v22.6.0

Experimental feature. [Learn more.](/docs/beta-and-experimental-features#experimental-features)