6.5. Conversion Functions

Presto will implicity convert numeric and character values to thecorrect type if such a conversion is possible. Presto will not convertbetween character and numeric types. For example, a query that expectsa varchar will not automatically convert a bigint value to anequivalent varchar.

When necessary, values can be explicitly cast to a particular type.

Conversion Functions

cast(value AS type) → type

Explicitly cast a value as a type. This can be used to cast avarchar to a numeric value type and vice versa.
trycast(_value AS type) → type

Like cast(), but returns null if the cast fails.

Miscellaneous

typeof(expr) → varchar

Returns the name of the type of the provided expression:



  1. SELECT typeof(123); integer
    SELECT typeof('cat'); varchar(3)
    SELECT typeof(cos(2) + 1.5); double



原文: https://prestodb.io/docs/current/functions/conversion.html