Skip to main content

CAST (expr AS [SQL_]<conv_type>) *or* CONVERT (expr, [SQL_]<conv_type>)

Converts expr into conv_type data typeConversion Types:
NumericStringDate/Time
BIGINTCHAR(N)DATE
DECIMAL(P,S)VARCHAR(N)DATETIME
DOUBLETIME
FLOATTIMESTAMP
INTEGERTYPE_DATE
NUMERIC(P,S)TYPE_TIME
REALTYPE_TIMESTAMP
SMALLINT
TINYINT
UNSIGNED BIGINT
When using the SQL_ prefix, UNSIGNED BIGINT becomes SQL_UNSIGNED_BIGINT

CHAR(expr)

Returns the character associated with the ASCII code given in expr

CHAR1(expr)

Converts the given expr to VARCHAR(1) type

CHAR2(expr)

Converts the given expr to VARCHAR(2) type

CHAR4(expr)

Converts the given expr to VARCHAR(4) type

CHAR8(expr)

Converts the given expr to VARCHAR(8) type

CHAR16(expr)

Converts the given expr to VARCHAR(16) type

CHAR32(expr)

Converts the given expr to VARCHAR(32) type

CHAR64(expr)

Converts the given expr to VARCHAR(64) type

CHAR128(expr)

Converts the given expr to VARCHAR(128) type

CHAR256(expr)

Converts the given expr to VARCHAR(256) type

DATE(expr)

Converts expr to date (YYYY-MM-DD) format

DATETIME(expr)

Converts expr to datetime (YYYY-MM-DD HH24:MI:SS.mmm) format

DECIMAL(expr)

Converts the given expr to DECIMAL type

DOUBLE(expr)

Converts the given expr to DOUBLE type

FLOAT(expr)

Converts the given expr to REAL type

INT(expr)

Converts the given expr to INTEGER type

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 epoch

STRING(expr)

Converts expr to a string format appropriate for the expr type

TIME(expr)

Converts expr to time (HH24:MI:SS) format

TIMESTAMP(expr)

Converts expr to TIMESTAMP type

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 CallTO_CHAR(DATETIME(971181296000), ‘“Last login: “YYYY-MM-DD’)
ReturnLast login: 2000-10-10

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)

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)

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)

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)

Converts the given expr to UNSIGNED BIGINT type

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 (with TO_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.