Type Casts
Expression
Example
Description
CAST(expr AS type
)
CAST(1.25 AS FLOAT)
Converts an expression to another data type. For conversions to a TEXT type, use TRY_CAST.
TRY_CAST(text_expr AS type
)
CAST('1.25' AS FLOAT)
Converts a text to a non-text type, returning null if the conversion could not be successfully performed.
ENCODE_TEXT(none_encoded_str
)
ENCODE_TEXT(long_str)
Converts a none-encoded text type to a dictionary-encoded text type.
The following table shows cast type conversion support.
FROM/TO:
TINYINT
SMALLINT
INTEGER
BIGINT
FLOAT
DOUBLE
DECIMAL
TEXT
BOOLEAN
DATE
TIME
TIMESTAMP
TINYINT
-
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
n/a
SMALLINT
Yes
-
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
n/a
INTEGER
Yes
Yes
-
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
BIGINT
Yes
Yes
Yes
-
Yes
Yes
Yes
Yes
No
No
No
No
FLOAT
Yes
Yes
Yes
Yes
-
Yes
No
Yes
No
No
No
No
DOUBLE
Yes
Yes
Yes
Yes
Yes
-
No
Yes
No
No
No
n/a
DECIMAL
Yes
Yes
Yes
Yes
Yes
Yes
-
Yes
No
No
No
n/a
TEXT
Yes (Use TRY_CAST)
Yes (Use TRY_CAST)
Yes (Use TRY_CAST)
Yes (Use TRY_CAST)
Yes (Use TRY_CAST)
Yes (Use TRY_CAST)
Yes (Use TRY_CAST)
-
Yes (Use TRY_CAST)
Yes (Use TRY_CAST)
Yes (Use TRY_CAST)
Yes (Use TRY_CAST)
BOOLEAN
No
No
Yes
No
No
No
No
Yes
-
n/a
n/a
n/a
DATE
No
No
No
No
No
No
No
Yes
n/a
-
No
Yes
TIME
No
No
No
No
No
No
No
Yes
n/a
No
-
n/a
TIMESTAMP
No
No
No
No
No
No
No
Yes
n/a
Yes
No
-
Last updated