Skip to main content

Conversion Functions

Introduced or updated: v1.2.150

Below is a list of functions that allow you to convert an expression from one data type to another.

tip

Databend also offers a variety of functions for converting expressions into different date and time formats. Check out the SQL Functions > Date & Time Functions section to explore them.

FunctionDescriptionExampleResult
CAST( expr AS data_type )Converts a value from one data type to anotherCAST(1 AS VARCHAR)1
expr::data_typeAlias for CAST1::VARCHAR1
TRY_CAST( expr AS data_type )Converts a value from one data type to another. Returns NULL on error.TRY_CAST(1 AS VARCHAR)1
TO_BITMAP( expr )Converts a value to BITMAP data typeTO_BITMAP('1101')1101
BUILD_BITMAP( expr )Converts an array of positive integers to a BITMAP valueBUILD_BITMAP([1,4,5])::String1,4,5
TO_BOOLEAN( expr )Converts a value to BOOLEAN data typeTO_BOOLEAN('true')1
TO_FLOAT32( expr )Converts a value to FLOAT32 data typeTO_FLOAT32('1.2')1.2
TO_FLOAT64( expr )Converts a value to FLOAT64 data typeTO_FLOAT64('1.2')1.2
TO_INT8( expr )Converts a value to INT8 data typeTO_INT8('123')123
TO_INT16( expr )Converts a value to INT16 data typeTO_INT16('123')123
TO_INT32( expr )Converts a value to INT32 data typeTO_INT32('123')123
TO_INT64( expr )Converts a value to INT64 data typeTO_INT64('123')123
TO_STRING( expr )Converts a value to STRING data typeTO_STRING(10)10
TO_STRING( expr, expr )Alias for DATE_FORMATTO_STRING('2022-12-25', 'Month/Day/Year: %m/%d/%Y')Month/Day/Year: 12/25/2022
TO_UINT8( expr )Converts a value to UINT8 data typeTO_UINT8('123')123
TO_UINT16( expr )Converts a value to UINT16 data typeTO_UINT16('123')123
TO_UINT32( expr )Converts a value to UINT32 data typeTO_UINT32('123')123
TO_UINT64( expr )Converts a value to UINT64 data typeTO_UINT64('123')123
TO_VARIANT( expr )Converts a value to VARIANT data typeTO_VARIANT(TO_BITMAP('100,200,300'))[100,200,300]