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

snowflake.snowpark.functions.cast

snowflake.snowpark.functions.cast(column: Union[Column, str], to: Union[str, DataType]) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/functions.py#L6003-L6021)

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
Language: English