Type Conversion Functions
This section describes type conversion functions, including their syntax, parameters, and usage examples.
Function List
| Function | Description |
|---|---|
| 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. | |
| 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. | |
| 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)
| 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 |
| 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)
| 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.
| 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)
| 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)
| 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
| Type | Scenario |
|---|---|
| Query statement | typeof(from_unixtime(__time)) |
| Returned result | timestamp(3) with time zone |
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot