Skip to main content

Conversion functions

This family of functions can be used to convert an expression of any ScopeDB data type to another data type.

CAST, ::

Converts a value of one data type into another data type. If the cast is not possible, an error is raised.

Syntax

CAST( <source_expr> AS <target_data_type> )

or

<source_expr> :: <target_data_type>

Arguments

<source_expr>

Expression of any supported data type to be converted into a different data type.

<target_data_type>

The data type to which to convert the expression.

Examples

Convert a string to a timestamp:

SELECT CAST('1900-10-16T19:00:00Z' AS timestamp);
SELECT '2024-10-16T19:00:00Z'::timestamp;

Convert a string to an interval:

SELECT CAST('PT24h' AS interval);
SELECT 'PT60s'::interval;