Conversion Functions

This page contains the explicit conversion functions supported by e6data.

CAST FUNCTION

CAST( <expr> as <target datatype> )

Converts the input expression to the specified target datatype.

cast('2022-01-11' as date)

The following table contains a matrix of all supported conversions:

TRY CAST FUNCTION

TRY_CAST( <input datatype> , <output datatype> )

Converts the input expression to the specified target datatype, but returns a NULL value instead of raising an error when the conversion can not be performed.

> select try_cast('45.6789' AS double)
45.6789
> select try_cast('false' as boolean)
false
> select try_cast('2022-01-02 12:27:11' as TIMESTAMP)
2022-01-02T12:27:11.000+00:00

Usages

Support datatype: VARCHAR, NUMBER (or any of its synonyms), DOUBLE, BOOLEAN, DATE, TIMESTAMP

  • try_cast to DATE accept 'YYYY-MM-DD' format for other formats returns null

    > select try_cast('05-Mar-2014' as date) 
    NULL
  • try_cast to TIMESTAMP accept 'YYYY-MM-DD HH:mm:ss' format for other formats returns null

    > select try_cast('05-Mar-2014 12:27:11' as timestamp)