Type conversion functions

**Returned value**

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

**Examples**

**Usage example**

```
SELECT
    toInt8(257) AS x,
    toTypeName(x),
    reinterpretAsInt16(x) AS res,
    toTypeName(res)
```

```
┌─x─┬─toTypeName(x)─┬─res─┬─toTypeName(res)─┐
│ 1 │ Int8          │   1 │ Int16           │
└───┴───────────────┴─────┴─────────────────┘
```

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

Introduced in: v1.1.0

Reinterprets the input value as a value of type Int256.
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**

```
reinterpretAsInt256(x)
```

**Arguments**

- `x` — Value to reinterpret as Int256. [`(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`. [`Int256`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT
    toInt128(257) AS x,
    toTypeName(x),
    reinterpretAsInt256(x) AS res,
    toTypeName(res)
```

```
┌───x─┬─toTypeName(x)─┬─res─┬─toTypeName(res)─┐
│ 257 │ Int128        │ 257 │ Int256          │
└─────┴───────────────┴─────┴─────────────────┘
```

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

Introduced in: v1.1.0

Reinterprets the input value as a value of type Int32.
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**

```
reinterpretAsInt32(x)
```

**Arguments**

- `x` — Value to reinterpret as Int32. [`(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`. [`Int32`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT
    toInt16(257) AS x,
    toTypeName(x),
    reinterpretAsInt32(x) AS res,
    toTypeName(res)
```

```
┌───x─┬─toTypeName(x)─┬─res─┬─toTypeName(res)─┐
│ 257 │ Int16         │ 257 │ Int32           │
└─────┴───────────────┴─────┴─────────────────┘
```

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

Introduced in: v1.1.0

Reinterprets the input value as a value of type Int64.
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**

```
reinterpretAsInt64(x)
```

**Arguments**

- `x` — Value to reinterpret as Int64. [`(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`. [`Int64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT
    toInt32(257) AS x,
    toTypeName(x),
    reinterpretAsInt64(x) AS res,
    toTypeName(res)
```

```
┌───x─┬─toTypeName(x)─┬─res─┬─toTypeName(res)─┐
│ 257 │ Int32         │ 257 │ Int64           │
└─────┴───────────────┴─────┴─────────────────┘
```

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

Introduced in: v1.1.0

Reinterprets the input value as a value of type Int8.
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**

```
reinterpretAsInt8(x)
```

**Arguments**

- `x` — Value to reinterpret as Int8. [`(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`. [`Int8`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

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

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

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

Introduced in: v1.1.0

Reinterprets the input value as a string (assuming little endian order).
Null bytes at the end are ignored, for example, the function returns for UInt32 value 255 a string with a single character.

**Syntax**

```
reinterpretAsString(x)
```

**Arguments**

- `x` — Value to reinterpret to string. [`(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)

**Returned value**

String containing bytes representing `x`. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT
    reinterpretAsString(toDateTime('1970-01-01 01:01:05')),
    reinterpretAsString(toDate('1970-03-07'))
```

```
┌─reinterpretAsString(toDateTime('1970-01-01 01:01:05'))─┬─reinterpretAsString(toDate('1970-03-07'))─┐
│ A                                                      │ A                                         │
└────────────────────────────────────────────────────────┴───────────────────────────────────────────┘
```

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

Introduced in: v1.1.0

Reinterprets the input value as a value of type UInt128.
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**

```
reinterpretAsUInt128(x)
```

**Arguments**

- `x` — Value to reinterpret as UInt128. [`(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`. [`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**