Skip to content

Cast Functions and Operators

The following functions are available in Okera to convert types explicitly between each other (if allowed).

Function Description
casttobigint() Casts the specified value to BIGINT
casttoboolean() Casts the specified value to BOOLEAN
casttochar() Casts the specified value to CHAR
casttodate() Casts the specified value to DATE
casttodecimal() Casts the specified value to DECIMAL
casttodouble() Casts the specified value to DOUBLE
casttofloat() Casts the specified value to FLOAT
casttoint() Casts the specified value to INT
casttosmallint() Casts the specified value to SMALLINT
casttostring() Casts the specified value to STRING
casttotimestamp() Casts the specified value to TIMESTAMP
casttotinyint() Casts the specified value to TINYINT
casttovarchar() Casts the specified value to VARCHAR

These functions are the equivalent to the usual CAST(... AS ...) operator. For example:

> SELECT typeof(3+7);
SMALLINT

> SELECT typeof(casttoint(3+7));
INT

The first typeof() returns SMALLINT as the implicitly determined data type of the expression result. The second typeof() returns INT as the explicit casttoint() is changing the SMALLINT to an INT type.

See Data Types for a matrix that shows what data types are allowed to be casted into other types and which.