Skip to main content

CAST

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

Syntax

CAST( <expr> AS <type>)
<expr>::<type>

Arguments

ArgumentsDescription
<expr>A value to convert.
<type>The target data type

Return Type

Converted value.

Examples

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

SELECT 1::VARCHAR;
+-----------+
| 1::String |
+-----------+
| 1 |
+-----------+

SELECT CAST(1 AS BIGINT UNSIGNED);
+-------------------+
| cast(1 as UInt64) |
+-------------------+
| 1 |
+-------------------+

SELECT typeof(CAST(1 AS BIGINT UNSIGNED));
+-------------------------------+
| typeof(cast(1 as UInt64)) |
+-------------------------------+
| UInt64 |
+-------------------------------+