Type Conversion Functionsedit

Functions for converting an expression of one data type to another.

CASTedit

Synopsis. 

CAST ( expression AS data_type )

Expression to cast

Target data type to cast to

Description. Casts the result of the given expression to the target type. If the cast is not possible (for example because of target type is too narrow or because the value itself cannot be converted), the query fails.

SELECT CAST('123' AS INT) AS int;

      int
---------------
123
SELECT CAST(123 AS VARCHAR) AS string;

    string
---------------
123
SELECT YEAR(CAST('2018-05-19T11:23:45Z' AS TIMESTAMP)) AS year;

     year
---------------
2018