Type Functions
Syntax | Description | Example | Normal Query | Pushdown Query | Defined as Computed Column | Suggested as Computed Column |
---|---|---|---|---|---|---|
CAST(value AS type) | Converts a value to a given type. | Example 1: Converts time to string CAST(CURRENT_DATE as varchar) = 2018-10-10 | ✔️ | ✔️ | ✔️ | ✔️ |
DATE<String> | Converts a string to DATE type, equaling to CAST(string AS date) | Example 1:DATE'2018-10-10' = 2018-10-10 Example 2: Gets the corresponding month of the string (use with time function, MONTH() ) MONTH(DATE'2018-10-10') = 10 | ✔️ | ✔️ | ❌ | ❌ |
TIMESTAMP<String> | Converts a string to TIMESTAMP type, equaling to CAST(string AS timestamp) | Example 1:TIMESTAMP'2018-10-10 15:57:07 = 2018-10-10 15:57:07 Example 2: Gets the corresponding second of the string (use with time function, SECOND() ) SECOND(TIMESTAMP'2018-10-10 15:57:07') = 7 | ✔️ | ✔️ | ❌ | ❌ |
Note:
- Only the following types of conversions are supported:
char
,varchar
,boolean
,int
,integer
,tinyint
,smallint
,bigint
,float
,double
,decimal
,numeric
,date
,time
,timestamp
- However, conversion from
bigint
totimestamp
is not supported at this time- If converting from
char
toint
, non-numeric values inchar
will return null- Length n does not take effect when other data types are converted to
char(n)
/varchar(n)