Other functions

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)

Not supported in ClickHouse Cloud

Returns the ID of a transaction.

Note

This function is part of an experimental feature set.
Enable experimental transaction support by adding this setting to your [configuration](/docs/operations/configuration-files):

```
<clickhouse>
    <allow_experimental_transactions>1</allow_experimental_transactions>
</clickhouse>
```

For more information see the page [Transactional (ACID) support](/docs/guides/developer/transactional#transactions-commit-and-rollback).

**Syntax**

```
transactionID()
```

**Arguments**

- None.

**Returned value**

Returns a tuple consisting of `start_csn`, `local_tid` and `host_id`.

- `start_csn`: Global sequential number, the newest commit timestamp that was seen when this transaction began.
- `local_tid`: Local sequential number that is unique for each transaction started by this host within a specific start\_csn.
- `host_id`: UUID of the host that has started this transaction.
  [`Tuple(UInt64, UInt64, UUID)`](/docs/sql-reference/data-types/tuple)

**Examples**

**Usage example**

```
BEGIN TRANSACTION;
SELECT transactionID();
ROLLBACK;
```

```
┌─transactionID()────────────────────────────────┐
│ (32,34,'0ee8b069-f2bb-4748-9eae-069c85b5252b') │
└────────────────────────────────────────────────┘
```

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

Introduced in: v22.6.0

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

Not supported in ClickHouse Cloud

Returns the newest snapshot (Commit Sequence Number) of a [transaction](/docs/guides/developer/transactional#transactions-commit-and-rollback) that is available for reading.

Note

This function is part of an experimental feature set. Enable experimental transaction support by adding this setting to your configuration:

```
<clickhouse>
    <allow_experimental_transactions>1</allow_experimental_transactions>
</clickhouse>
```

For more information see the page [Transactional (ACID) support](/docs/guides/developer/transactional#transactions-commit-and-rollback).

**Syntax**

```
transactionLatestSnapshot()
```

**Arguments**

- None.

**Returned value**

Returns the latest snapshot (CSN) of a transaction. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
BEGIN TRANSACTION;
SELECT transactionLatestSnapshot();
ROLLBACK;
```

```
┌─transactionLatestSnapshot()─┐
│                          32 │
└─────────────────────────────┘
```

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

Introduced in: v22.6.0

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

Not supported in ClickHouse Cloud

Returns the oldest snapshot (Commit Sequence Number) that is visible for some running [transaction](/docs/guides/developer/transactional#transactions-commit-and-rollback).

Note

This function is part of an experimental feature set. Enable experimental transaction support by adding this setting to your configuration:

```
<clickhouse>
    <allow_experimental_transactions>1</allow_experimental_transactions>
</clickhouse>
```

For more information see the page [Transactional (ACID) support](/docs/guides/developer/transactional#transactions-commit-and-rollback).

**Syntax**

```
transactionOldestSnapshot()
```

**Arguments**

- None.

**Returned value**

Returns the oldest snapshot (CSN) of a transaction. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
BEGIN TRANSACTION;
SELECT transactionOldestSnapshot();
ROLLBACK;
```

```
┌─transactionOldestSnapshot()─┐
│                          32 │
└─────────────────────────────┘
```

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

Introduced in: v1.1.0

Transforms a value according to the explicitly defined mapping of some elements to other elements.

There are two variations of this function:

- `transform(x, array_from, array_to, default)` - transforms `x` using mapping arrays with a default value for unmatched elements
- `transform(x, array_from, array_to)` - same transformation but returns the original `x` if no match is found

The function searches for `x` in `array_from` and returns the corresponding element from `array_to` at the same index.
If `x` is not found in `array_from`, it returns either the `default` value (4-parameter version) or the original `x` (3-parameter version).
If multiple matching elements exist in `array_from`, it returns the element corresponding to the first match.

Requirements:

- `array_from` and `array_to` must have the same number of elements
- For 4-parameter version: `transform(T, Array(T), Array(U), U) -> U` where `T` and `U` can be different compatible types
- For 3-parameter version: `transform(T, Array(T), Array(T)) -> T` where all types must be the same

**Syntax**

```
transform(x, array_from, array_to[, default])
```

**Arguments**

- `x` — Value to transform. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Decimal`](/docs/sql-reference/data-types/decimal) or [`Float*`](/docs/sql-reference/data-types/float) or [`String`](/docs/sql-reference/data-types/string) or [`Date`](/docs/sql-reference/data-types/date) or [`DateTime`](/docs/sql-reference/data-types/datetime)
- `array_from` — Constant array of values to search for matches. [`Array((U)Int*)`](/docs/sql-reference/data-types/array) or [`Array(Decimal)`](/docs/sql-reference/data-types/array) or [`Array(Float*)`](/docs/sql-reference/data-types/array) or [`Array(String)`](/docs/sql-reference/data-types/array) or [`Array(Date)`](/docs/sql-reference/data-types/array) or [`Array(DateTime)`](/docs/sql-reference/data-types/array)
- `array_to` — Constant array of values to return for corresponding matches in `array_from`. [`Array((U)Int*)`](/docs/sql-reference/data-types/array) or [`Array(Decimal)`](/docs/sql-reference/data-types/array) or [`Array(Float*)`](/docs/sql-reference/data-types/array) or [`Array(String)`](/docs/sql-reference/data-types/array) or [`Array(Date)`](/docs/sql-reference/data-types/array) or [`Array(DateTime)`](/docs/sql-reference/data-types/array)
- `default` — Optional. Value to return if `x` is not found in `array_from`. If omitted, returns x unchanged. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Decimal`](/docs/sql-reference/data-types/decimal) or [`Float*`](/docs/sql-reference/data-types/float) or [`String`](/docs/sql-reference/data-types/string) or [`Date`](/docs/sql-reference/data-types/date) or [`DateTime`](/docs/sql-reference/data-types/datetime)

**Returned value**

Returns the corresponding value from `array_to` if x matches an element in `array_from`, otherwise returns default (if provided) or x (if default not provided). [`Any`](/docs/sql-reference/data-types)

**Examples**

**transform(T, Array(T), Array(U), U) -> U**

```
SELECT
transform(SearchEngineID, [2, 3], ['Yandex', 'Google'], 'Other') AS title,
count() AS c
FROM test.hits
WHERE SearchEngineID != 0
GROUP BY title
ORDER BY c DESC
```

```
┌─title─────┬──────c─┐
│ Yandex    │ 498635 │
│ Google    │ 229872 │
│ Other     │ 104472 │
└───────────┴────────┘
```

**transform(T, Array(T), Array(T)) -> T**