snowflake.snowpark.functions.try_to_binary¶
- snowflake.snowpark.functions.try_to_binary(e: Union[Column, str], fmt: Optional[str] = None) Column [source] (https://github.com/snowflakedb/snowpark-python/blob/v1.30.0/snowpark-python/src/snowflake/snowpark/functions.py#L11358-L11378)¶
A special version of TO_BINARY that performs the same operation (i.e. converts an input expression to a binary value), but with error handling support (i.e. if the conversion cannot be performed, it returns a NULL value instead of raising an error).
Example:
>>> df = session.create_dataframe(["01", "A B", "Hello", None], schema=["hex_encoded_string"]) >>> df.select(try_to_binary(df["hex_encoded_string"], 'HEX').alias("b")).collect() [Row(B=bytearray(b'\x01')), Row(B=None), Row(B=None), Row(B=None)]