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

Scalar Data Conversion Functions

Implicit Conversions

In certain situations, Ocient® 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.

Map Functions

A map is a set of key-value pairs that the Ocient System stores as two parallel arrays: one array of keys and one array of values. The key at each position in the key array corresponds to the value at the same position in the value array. You can store a map in a single column with the data type TUPLE<<key_type[], value_type[]>>, where the first tuple element is the key array and the second tuple element is the value array. The map functionality is similar to a Python® dictionary dict or a hash table. The map functions insert, retrieve, and remove key-value pairs in a map. Each map function accepts a map as a single TUPLE type argument or as two separate ARRAY type arguments. These rules apply to all map functions:
  • The key array and the value array can use different element data types, and each array supports scalar element data types such as INT, CHAR, DATE, TIMESTAMP, DECIMAL, UUID, and POINT.
  • The keys in a map must be unique. If the key array contains duplicate keys, the function returns an error.
  • A NULL key is a valid map key. A map can contain at most one entry with a NULL key.
  • If the map argument is NULL, the function returns NULL.

MAP_DELETE

Removes the entry for the specified key from a map. If the key is not present in the map, the function returns the map unchanged. If you specify a NULL key, the function removes the entry with the NULL key. The function returns the resulting map as a TUPLE type containing the key and value arrays. Syntaxes Remove a Key from a Map Tuple Removes the entry for the specified key from a map that you specify as a tuple.
SQL
Remove a Key from Separate Key and Value Arrays Removes the entry for the specified key from a map that you specify as separate key and value arrays.
SQL
Examples Remove a Key from a Map Tuple Remove the key 1 and its value from a map that contains two entries.
SQL
Output: TUPLE<<INT[], INT[]>>(INT[](2), INT[](20)) Remove a Key from Separate Key and Value Arrays Remove the key 'bob' and its value from a map with character keys and integer values.
SQL
Output: TUPLE<<CHAR[], INT[]>>(CHAR[]('alice'), INT[](10))

MAP_GET

Returns the value for the specified key in a map. If the key is not present in the map, the function returns NULL. If you specify a NULL key, the function returns the value for the entry with the NULL key. The function also returns NULL when the stored value for the key is NULL, so a NULL result can mean either that the key is not present or that its value is NULL. Syntaxes Retrieve a Value from a Map Tuple Returns the value for the specified key from a map that you specify as a tuple.
SQL
Retrieve a Value from Separate Key and Value Arrays Returns the value for the specified key from a map that you specify as separate key and value arrays.
SQL
Examples Retrieve a Value from a Map Tuple Retrieve the value for the key 'bob' from a map with character keys and integer values.
SQL
Output: 20 Retrieve a Value from Separate Key and Value Arrays Retrieve the value for the key 3. The key is not present in the map, so the function returns NULL.
SQL
Output: NULL

MAP_PUT

Inserts a key-value pair into a map. If the key is already present in the map, the function replaces its value and keeps its position in the key array. The function returns the resulting map as a TUPLE type containing the key and value arrays. The data type of the key argument must match the element data type of the key array, and the data type of the value argument must match the element data type of the value array. Otherwise, the function returns an error. You can insert a NULL key or a NULL value. If the map already contains an entry with a NULL key, the function replaces its value. Syntaxes Insert a Key-Value Pair into a Map Tuple Inserts a key-value pair into a map that you specify as a tuple.
SQL
Insert a Key-Value Pair into Separate Key and Value Arrays Inserts a key-value pair into a map that you specify as separate key and value arrays.
SQL
Examples Insert a New Key into a Map Tuple Insert the key 2 with the value 20 into a map that contains one entry.
SQL
Output: TUPLE<<INT[], INT[]>>(INT[](1, 2), INT[](10, 20)) Update an Existing Key in Separate Key and Value Arrays Insert the key 1 with the value 30. The key is already present in the map, so the function replaces its value while keeping its position.
SQL
Output: TUPLE<<INT[], INT[]>>(INT[](1, 2), INT[](30, 20)) Date and Time Functions Character and Binary Functions Math Functions and Operators Formatting Functions Array Functions and Operators Tuple Functions and Operators
Last modified on September 23, 2026