Skip to main content
These functions convert one data type to another.

Scalar Data Conversion Functions

Implicit Conversions

In certain situations, SQL can automatically convert expressions to a specific data type without an explicit SQL statement.

Cast from Strings

You can cast string literals to any other data type by placing the name of the data type before the string literal. Examples Cast a Double Cast the value 1.5 from a string to a floating-point value.
SQL
*Output: *1.5 Cast an Array Cast the array INT[0,1,2,3] from a string to an array of integers.
SQL
*Output: *['0','1','2','3'] Cast a Point Value Cast the point value POINT(0 0) to the geospatial data type POINT. In this case, the cast keyword is ST_POINT, and the data type is POINT.
SQL
*Output: *POINT(0.0 0.0)

Cast from Date and Time Strings

You can cast date and time values to their interval value with the INTERVAL keyword. Retrieve Interval Values from Various Date and Time Strings Retrieve the interval value 5 from the '5 DAYS' string.
SQL
*Output: *5 Retrieve the interval value 2 from the '2 WEEKS' string.
SQL
*Output: *2 Retrieve the interval value 10 from the '10 SECONDS' string.
SQL
Output: 10

CAST Functions

These SQL statements allow casting an expression to any other data type.

CAST

Transforms an expression to any other data type. This function operates similarly to the :: Operator. Syntax
SQL
As shown in the syntax examples, CAST can support the optional ! operator.The ! operator returns a NULL value if the operation cannot cast to the specified data type. This behavior prevents situations where the system would normally raise an error.
Examples Cast an Integer to Varchar Transform the value 2 as a VARCHAR string.
SQL
Output: '2' Cast a Varchar to Date Transform the '2020-02-02' string to the DATE data type.
SQL
*Output: *'2020-02-02' Cast an Incompatible Type with the ! Operator Transform the 'a' string to an integer, or INT data type, using the ! operator.
SQL
Output: NULL This operation generates NULL because the database cannot transform this value to an integer. Without adding this operator, the statement raises an error because the database cannot transform the input expression to a numeric type.

:: Operator

Transforms an expression to any other data type. This function operates similarly to the CAST function. :: Syntax
SQL
As shown in the syntax examples, :: can support the optional ! operator.The ! operator returns a NULL value if the operation cannot cast to the specified data type. This behavior prevents situations where the system would normally raise an error.
Examples Cast an Integer to Float Transform the '2' string to a floating-point number.
SQL
Output: 2.0 Cast to an Incompatible Type with the ! Operator Transform the 'a' string to an integer, or INT data type, using the ! operator.
SQL
Output: NULL This operation generates NULL because the database cannot transform this value to an integer. Without adding this operator, the statement raises an error because the database cannot transform the input expression to a numeric type. Date and Time Functions Character and Binary Functions Math Functions and Operators Formatting Functions
Last modified on May 20, 2026