Updated on 2026-08-28 GMT+08:00

Type Conversion Functions

This section describes type conversion functions, including their syntax, parameters, and usage examples.

Function List

Table 1 Type conversion functions

Function

Description

cast

Converts a value from one data type to another and adds the data type to dynamic parameters. If a value fails to be converted, the query operation is terminated and an exception is thrown.

try_cast

Converts a value from one data type to another and adds the data type to dynamic parameters. If a value fails to be converted, the exception is captured and the value is returned as null.

typeof

Data type of the specified field.

cast

This function converts a value from one data type to another and provides the data type to dynamic parameters.

The conversion expressions can be used wherever expressions are allowed.

Syntax: CAST(Expression as Datatype)

Table 2 Parameter description

Parameter

Description

Type

Mandatory

expression

Source type of the expression.

Any

Yes

Datatype

Target type.

SQL data type, such as bigint, varchar, double, double precision, boolean, timestamp, decimal, integer, char, or date

Yes

Table 3 Mapping between index and SQL data types

Index Data Type

SQL Data Type

Long

Bigint

String

Varchar

Float

Double or double precision

Return value type: target data type

Example: select cast(time as date)

Table 4 Query and analysis results

Type

Query Statement

Returned Result

Scenario

cast(time as date)

2023-08-31 23:11:17.000

try_cast

Converts a value from one data type to another and adds the data type to dynamic parameters. If a value fails to be converted, the exception is captured and the value is returned as null.

Syntax: TRY_CAST(Expression as Datatype)

The final data type upon conversion is the target type. The data type that needs to be converted is the source type.

Table 5 Parameter description

Parameter

Description

Type

Mandatory

expression

Source type.

Any

Yes

Datatype

Target type.

SQL data type, such as bigint, varchar, double, double precision, boolean, timestamp, decimal, integer, char, or date

Yes

Return value type: target data type

Example: select try_cast(time as date)

Table 6 Query and analysis result

Type

Scenario

Query statement

try_cast(time as date)

Returned result

null

typeof

Returns the data type of a specified field or expression.

Syntax: typeof(expression)

Table 7 Parameter description

Parameter

Description

Type

Mandatory

expression

Field or expression whose result type is to be determined.

Any

Yes

Return value type: target data type

Example: select typeof(from_unixtime(__time)) as t

Table 8 Query and analysis result

Type

Scenario

Query statement

typeof(from_unixtime(__time))

Returned result

timestamp(3) with time zone