snowflake.snowpark.functions.sha2_binary¶
- snowflake.snowpark.functions.sha2_binary(msg: Union[snowflake.snowpark.column.Column, str], digest_size: Union[snowflake.snowpark.column.Column, str] = None) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.43.0/src/snowflake/snowpark/_functions/scalar_functions.py#L4182-L4209)¶
Returns a binary SHA-2 hash of the input message. The digest size determines the hash algorithm used.
- Parameters:
msg (ColumnOrName) – The input message to hash.
digest_size (ColumnOrName, optional) – The digest size in bits. Valid values are 224, 256, 384, and 512. Defaults to 256 if not specified.
- Returns:
A binary representation of the SHA-2 hash.
- Return type:
- Examples::
>>> from snowflake.snowpark.functions import col, lit >>> df = session.create_dataframe([["Snowflake"], ["test"], ["hello"]], schema=["msg"]) >>> df.select(sha2_binary(col("msg")).alias("result")).collect() [Row(RESULT=bytearray(b'\x1d\xbdY\xf6a\xd6\x8b\x90rO!\x08C\x96\xb8eIqs\xe4\xd2qOM\x91\xcf\x05\xfa_\xc5\xe1\x8d')), Row(RESULT=bytearray(b'\x9f\x86\xd0\x81\x88L}e\x9a/\xea\xa0\xc5Z\xd0\x15\xa3\xbfO\x1b+\x0b\x82,\xd1]l\x15\xb0\xf0\n\x08')), Row(RESULT=bytearray(b',\xf2M\xba_\xb0\xa3\x0e&\xe8;*\xc5\xb9\xe2\x9e\x1b\x16\x1e\\\x1f\xa7B^s\x043b\x93\x8b\x98$'))] >>> df.select(sha2_binary(col("msg"), lit(224)).alias("result")).collect() [Row(RESULT=bytearray(b'bg\xd3\xd7\xa5\x99)\xe6\x86M\xd4\xb77\xd9\x8e>\xf8V\x9d\x9f\x88\xa7FfG\x83\x852')), Row(RESULT=bytearray(b'\x90\xa3\xed\x9e2\xb2\xaa\xf4\xc6\x1cA\x0e\xb9%Ba\x19\xe1\xa9\xdcS\xd4(j\xde\x99\xa8\t')), Row(RESULT=bytearray(b'\xea\t\xae\x9c\xc6v\x8cP\xfc\xee\x90>\xd0TUn[\xfc\x83G\x90\x7f\x12Y\x8a\xa2A\x93'))]