Type conversion functions

**Returned value**

Returns the reinterpreted value `x`. [`UInt128`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT
    toUInt64(257) AS x,
    toTypeName(x),
    reinterpretAsUInt128(x) AS res,
    toTypeName(res)
```

```
┌───x─┬─toTypeName(x)─┬─res─┬─toTypeName(res)─┐
│ 257 │ UInt64        │ 257 │ UInt128         │
└─────┴───────────────┴─────┴─────────────────┘
```

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

Introduced in: v1.1.0

Reinterprets the input value as a value of type UInt16.
Unlike [`CAST`](#CAST), the function does not attempt to preserve the original value - if the target type is not able to represent the input type, the output is undefined.

**Syntax**

```
reinterpretAsUInt16(x)
```

**Arguments**

- `x` — Value to reinterpret as UInt16. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Date`](/docs/sql-reference/data-types/date) or [`DateTime`](/docs/sql-reference/data-types/datetime) or [`UUID`](/docs/sql-reference/data-types/uuid) or [`String`](/docs/sql-reference/data-types/string) or [`FixedString`](/docs/sql-reference/data-types/fixedstring)

**Returned value**

Returns the reinterpreted value `x`. [`UInt16`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT
    toUInt8(257) AS x,
    toTypeName(x),
    reinterpretAsUInt16(x) AS res,
    toTypeName(res)
```

```
┌─x─┬─toTypeName(x)─┬─res─┬─toTypeName(res)─┐
│ 1 │ UInt8         │   1 │ UInt16          │
└───┴───────────────┴─────┴─────────────────┘
```

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

Introduced in: v1.1.0

Reinterprets the input value as a value of type UInt256.
Unlike [`CAST`](#CAST), the function does not attempt to preserve the original value - if the target type is not able to represent the input type, the output is undefined.

**Syntax**

```
reinterpretAsUInt256(x)
```

**Arguments**

- `x` — Value to reinterpret as UInt256. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Date`](/docs/sql-reference/data-types/date) or [`DateTime`](/docs/sql-reference/data-types/datetime) or [`UUID`](/docs/sql-reference/data-types/uuid) or [`String`](/docs/sql-reference/data-types/string) or [`FixedString`](/docs/sql-reference/data-types/fixedstring)

**Returned value**

Returns the reinterpreted value `x`. [`UInt256`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT
    toUInt128(257) AS x,
    toTypeName(x),
    reinterpretAsUInt256(x) AS res,
    toTypeName(res)
```

```
┌───x─┬─toTypeName(x)─┬─res─┬─toTypeName(res)─┐
│ 257 │ UInt128       │ 257 │ UInt256         │
└─────┴───────────────┴─────┴─────────────────┘
```

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

Introduced in: v1.1.0

Reinterprets the input value as a value of type UInt32.
Unlike [`CAST`](#CAST), the function does not attempt to preserve the original value - if the target type is not able to represent the input type, the output is undefined.

**Syntax**

```
reinterpretAsUInt32(x)
```

**Arguments**

- `x` — Value to reinterpret as UInt32. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Date`](/docs/sql-reference/data-types/date) or [`DateTime`](/docs/sql-reference/data-types/datetime) or [`UUID`](/docs/sql-reference/data-types/uuid) or [`String`](/docs/sql-reference/data-types/string) or [`FixedString`](/docs/sql-reference/data-types/fixedstring)

**Returned value**

Returns the reinterpreted value `x`. [`UInt32`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT
    toUInt16(257) AS x,
    toTypeName(x),
    reinterpretAsUInt32(x) AS res,
    toTypeName(res)
```

```
┌───x─┬─toTypeName(x)─┬─res─┬─toTypeName(res)─┐
│ 257 │ UInt16        │ 257 │ UInt32          │
└─────┴───────────────┴─────┴─────────────────┘
```

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

Introduced in: v1.1.0

Reinterprets the input value as a value of type UInt64.
Unlike [`CAST`](#CAST), the function does not attempt to preserve the original value - if the target type is not able to represent the input type, the output is undefined.

**Syntax**

```
reinterpretAsUInt64(x)
```

**Arguments**

- `x` — Value to reinterpret as UInt64. [`Int*`](/docs/sql-reference/data-types/int-uint) or [`UInt*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Date`](/docs/sql-reference/data-types/date) or [`DateTime`](/docs/sql-reference/data-types/datetime) or [`UUID`](/docs/sql-reference/data-types/uuid) or [`String`](/docs/sql-reference/data-types/string) or [`FixedString`](/docs/sql-reference/data-types/fixedstring)

**Returned value**

Returns the reinterpreted value of `x`. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT
    toUInt32(257) AS x,
    toTypeName(x),
    reinterpretAsUInt64(x) AS res,
    toTypeName(res)
```

```
┌───x─┬─toTypeName(x)─┬─res─┬─toTypeName(res)─┐
│ 257 │ UInt32        │ 257 │ UInt64          │
└─────┴───────────────┴─────┴─────────────────┘
```

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

Introduced in: v1.1.0

Reinterprets the input value as a value of type UInt8.
Unlike [`CAST`](#CAST), the function does not attempt to preserve the original value - if the target type is not able to represent the input type, the output is undefined.

**Syntax**

```
reinterpretAsUInt8(x)
```

**Arguments**

- `x` — Value to reinterpret as UInt8. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Date`](/docs/sql-reference/data-types/date) or [`DateTime`](/docs/sql-reference/data-types/datetime) or [`UUID`](/docs/sql-reference/data-types/uuid) or [`String`](/docs/sql-reference/data-types/string) or [`FixedString`](/docs/sql-reference/data-types/fixedstring)

**Returned value**

Returns the reinterpreted value `x`. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT
    toInt8(-1) AS val,
    toTypeName(val),
    reinterpretAsUInt8(val) AS res,
    toTypeName(res);
```

```
┌─val─┬─toTypeName(val)─┬─res─┬─toTypeName(res)─┐
│  -1 │ Int8            │ 255 │ UInt8           │
└─────┴─────────────────┴─────┴─────────────────┘
```

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

Introduced in: v1.1.0

Accepts a 16 byte string and returns a UUID by interpreting each 8-byte half in little-endian byte order. If the string isn't long enough, the function works as if the string is padded with the necessary number of null bytes to the end. If the string is longer than 16 bytes, the extra bytes at the end are ignored.

**Syntax**

```
reinterpretAsUUID(fixed_string)
```

**Arguments**

- `fixed_string` — Big-endian byte string. [`FixedString`](/docs/sql-reference/data-types/fixedstring)

**Returned value**

The UUID type value. [`UUID`](/docs/sql-reference/data-types/uuid)

**Examples**

**String to UUID**

```
SELECT reinterpretAsUUID(reverse(unhex('000102030405060708090a0b0c0d0e0f')))
```

```
┌─reinterpretAsUUID(reverse(unhex('000102030405060708090a0b0c0d0e0f')))─┐
│                                  08090a0b-0c0d-0e0f-0001-020304050607 │
└───────────────────────────────────────────────────────────────────────┘
```

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

Introduced in: v1.1.0

Converts an input value to a value of type BFloat16.
Throws an exception in case of an error.

See also:

- [`toBFloat16OrZero`](#toBFloat16OrZero).
- [`toBFloat16OrNull`](#toBFloat16OrNull).

**Syntax**

```
toBFloat16(expr)
```

**Arguments**

- `expr` — Expression returning a number or a string representation of a number. [`Expression`](/docs/sql-reference/data-types/special-data-types/expression)

**Returned value**