# Type conversion functions

Explicit conversion applies a declared value contract to an expression. Use it when importing text, changing numeric families or extracting a representation for another operation.

## CAST

```text
CAST(value AS Type)
```

CAST supports every declared native type. It validates ranges, text, precision and collection shape. SQL NULL propagates. Native conversions report invalid or overflowing inputs instead of silently wrapping them.

## Named conversion functions

| Function                                             | Arguments                                                      |
| ---------------------------------------------------- | -------------------------------------------------------------- |
| `to_int128`, `to_uint128`, `to_int256`, `to_uint256` | One numeric value or accepted numeric text.                    |
| `to_float32`, `to_float64`, `to_bfloat16`            | One value to convert to the chosen approximate type.           |
| `to_decimal256`                                      | A value and a scale through 76, within the declared precision. |
| `to_interval_<unit>`                                 | One integral quantity; for example, `to_interval_day(2)`.      |
| `to_type_name`                                       | One value whose native type descriptor is required.            |
| `typeof`                                             | One value whose SQL runtime value class is required.           |

The exact input units and defaults depend on the target type. In particular, DateTime64 integer input means ticks, while Time64 integer input means seconds.

## Examples

### Checked integer conversion

```sql
SELECT CAST('255' AS UInt8), to_uint256('12345678901234567890')
FORMAT csv;
```

```text
255,12345678901234567890
```

`CAST('256' AS UInt8)` raises `NUMERIC_OVERFLOW`.

### Inspecting a decimal type

```sql
SELECT to_type_name(CAST('1.20' AS Decimal(18, 2)))
FORMAT csv;
```

```text
"Decimal(18,2)"
```

See [data types](https://coordinatordb.com/docs/reference/data-types) for target-specific conversion rules and [Interval](https://coordinatordb.com/docs/reference/data-types/special-data-types/interval) for supported units.
