You are viewing documentation about an older version (1.13.0). View latest version

snowflake.snowpark.functions.cast¶

snowflake.snowpark.functions.cast(column: Union[Column, str], to: Union[str, DataType]) → Column[source]¶

Converts a value of one data type into another data type. The semantics of CAST are the same as the semantics of the corresponding to datatype conversion functions. If the cast is not possible, a SnowparkSQLException exception is thrown.

Example:

>>> from snowflake.snowpark.types import DecimalType, IntegerType
>>> df = session.create_dataframe([[1.5432]], schema=["d"])
>>> df.select(cast(df.d, DecimalType(15, 2)).as_("DECIMAL"), cast(df.d, IntegerType()).as_("INT")).show()
---------------------
|"DECIMAL"  |"INT"  |
---------------------
|1.54       |2      |
---------------------
Copy