Skip to main content

CAST

Convert a value from one data type to another data type.

Syntax

CAST(x AS t)
x::t

Arguments

ArgumentsDescription
xA value to convert.
tThe target data type.

Return Type

Converted value.

Examples

mysql> SELECT CAST(1 AS VARCHAR);
+-------------------+
| cast(1 as String) |
+-------------------+
| 1 |
+-------------------+

mysql> select 1::varchar;
+-----------+
| 1::String |
+-----------+
| 1 |
+-----------+
1 row in set (0.014 sec)

mysql> SELECT CAST(1 AS UInt64);
+-------------------+
| cast(1 as UInt64) |
+-------------------+
| 1 |
+-------------------+

mysql> SELECT toTypeName(CAST(1 AS UInt64));
+-------------------------------+
| toTypeName(cast(1 as UInt64)) |
+-------------------------------+
| UInt64 |
+-------------------------------+