CAST (expr AS [SQL_]<conv_type>) *or* CONVERT (expr, [SQL_]<conv_type>)
CAST (expr AS [SQL_]<conv_type>) *or* CONVERT (expr, [SQL_]<conv_type>)
Converts
expr into conv_type data typeConversion Types:| Numeric | String | Date/Time |
|---|---|---|
BIGINT | CHAR(N) | DATE |
DECIMAL(P,S) | VARCHAR(N) | DATETIME |
DOUBLE | TIME | |
FLOAT | TIMESTAMP | |
INTEGER | TYPE_DATE | |
NUMERIC(P,S) | TYPE_TIME | |
REAL | TYPE_TIMESTAMP | |
SMALLINT | ||
TINYINT | ||
UNSIGNED BIGINT |
When using the
SQL_ prefix,
UNSIGNED BIGINT becomes SQL_UNSIGNED_BIGINTCHAR(expr)
CHAR(expr)
Returns the character associated with the ASCII code
given in
exprCHAR1(expr)
CHAR1(expr)
Converts the given
expr to VARCHAR(1) typeCHAR2(expr)
CHAR2(expr)
Converts the given
expr to VARCHAR(2) typeCHAR4(expr)
CHAR4(expr)
Converts the given
expr to VARCHAR(4) typeCHAR8(expr)
CHAR8(expr)
Converts the given
expr to VARCHAR(8) typeCHAR16(expr)
CHAR16(expr)
Converts the given
expr to VARCHAR(16) typeCHAR32(expr)
CHAR32(expr)
Converts the given
expr to VARCHAR(32) typeCHAR64(expr)
CHAR64(expr)
Converts the given
expr to VARCHAR(64) typeCHAR128(expr)
CHAR128(expr)
Converts the given
expr to VARCHAR(128) typeCHAR256(expr)
CHAR256(expr)
Converts the given
expr to VARCHAR(256) typeDATE(expr)
DATE(expr)
Converts
expr to date (YYYY-MM-DD) formatDATETIME(expr)
DATETIME(expr)
Converts
expr to datetime (YYYY-MM-DD HH24:MI:SS.mmm) formatDECIMAL(expr)
DECIMAL(expr)
Converts the given
expr to DECIMAL typeDOUBLE(expr)
DOUBLE(expr)
Converts the given
expr to DOUBLE typeFLOAT(expr)
FLOAT(expr)
Converts the given
expr to REAL typeINT(expr)
INT(expr)
Converts the given
expr to INTEGER typeLONG(expr)
LONG(expr)
Converts the given
expr to BIGINT type; if expr is a TIMESTAMP or
DATETIME type, the value will be the number of milliseconds since the epochSTRING(expr)
STRING(expr)
Converts
expr to a string format appropriate for the expr typeTIME(expr)
TIME(expr)
Converts
expr to time (HH24:MI:SS) formatTIMESTAMP(expr)
TIMESTAMP(expr)
Converts
expr to TIMESTAMP typeTO_CHAR(expr, format)
TO_CHAR(expr, format)
Converts the given date/time
expr to a string matching the given format.
The returned string will be truncated at 32 characters.
See Date/Time Conversion Codes for the list of format codes.Example:| Function Call | TO_CHAR(DATETIME(971181296000), ‘“Last login: “YYYY-MM-DD’) |
| Return | Last login: 2000-10-10 |
TO_DATE(string, format)
TO_DATE(string, format)
Converts the given string to a date type with the given format code.
See Date/Time Conversion Codes for the list of format codes.Example:
TO_DATETIME(string, format)
TO_DATETIME(string, format)
Converts the given string to a datetime type with the given format code.
See Date/Time Conversion Codes for the list of format codes.Example:
TO_TIME(string, format)
TO_TIME(string, format)
Converts the given string to a time type with the given format code.
See Date/Time Conversion Codes for the list of format codes.Example:
TO_TIMESTAMP(string, format)
TO_TIMESTAMP(string, format)
Converts the given string to a timestamp type with the given format code.
See Date/Time Conversion Codes for the list of format codes.Example:
ULONG(expr)
ULONG(expr)
Converts the given
expr to UNSIGNED BIGINT typeVECTOR(expr, len)
VECTOR(expr, len)
Converts the given stringified array of
len number of float values in expr to
VECTOR type.Example:Date/Time Conversion Codes
The following formatting codes can be used to convert date/time strings to native date/time objects (withTO_DATE, TO_DATETIME, TO_TIME and TO_TIMESTAMP)
and for formatting date/time objects as strings (with TO_CHAR).
These characters are interpreted literally: - / , . ; :
Other characters need to be quoted in order to be interpreted literally.
For example, MM-DD-YYYY can be used to convert 01-02-2022 to a date,
while "Today is "MM-DD-YYYY is needed to convert Today is 01-02-2022.
In the following table, Opt in the Input column indicates that the field may be empty
when being read, and still be considered a valid input. This can be useful when reading
data from a source that, for example, sometimes includes milliseconds in their time strings
and sometimes does not (e.g., the MMM code is Opt). Yes in the Input column indicates
that some data must be present in the input string to be considered valid, unless it is after
a $ character, in which case all input after the $ is optional.