snowflake.snowpark.functions.decode¶
- snowflake.snowpark.functions.decode(expr: Union[snowflake.snowpark.column.Column, str], *args: Union[snowflake.snowpark.column.Column, str]) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.40.0/src/snowflake/snowpark/_functions/scalar_functions.py#L1143-L1168)¶
Decodes an expression by comparing it with search values and returning corresponding result values.
Similar to a Case statement, this function compares an expression to one or more search values and returns the corresponding result when a match is found.
- Parameters:
expr (ColumnOrName) – The expression to decode.
*args (ColumnOrName) – Variable length argument list containing pairs of search values and result values, with an optional default value at the end.
- Returns:
The decoded result.
- Return type:
Example
>>> from snowflake.snowpark.functions import col, lit >>> df = session.create_dataframe([[1, 1], [2, 4], [16, 24]], schema=["a", "b"]) >>> df.select(decode(col("a"), lit(1), lit("one"), lit(2), lit("two"), lit("default")).alias("RESULT")).collect() [Row(RESULT='one'), Row(RESULT='two'), Row(RESULT='default')]