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

snowflake.snowpark.functions.try_to_binary¶

snowflake.snowpark.functions.try_to_binary(e: Union[Column, str], fmt: Optional[str] = None) → Column[source]¶

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)]
Copy