snowflake.snowpark.functions.iff

snowflake.snowpark.functions.iff(condition: Union[Column, str], expr1: Union[Column, None, bool, int, float, str, bytearray, Decimal, date, datetime, time, bytes, NaTType, float64, list, tuple, dict], expr2: Union[Column, None, bool, int, float, str, bytearray, Decimal, date, datetime, time, bytes, NaTType, float64, list, tuple, dict]) → Column[source]

Returns one of two specified expressions, depending on a condition. This is equivalent to an if-then-else expression.

Parameters:
  • condition – A Column expression or SQL text representing the specified condition.

  • expr1 – A Column expression or a literal value, which will be returned if condition is true.

  • expr2 – A Column expression or a literal value, which will be returned if condition is false or NULL.

Examples:

>>> from snowflake.snowpark.functions import iff, lit
>>> df = session.create_dataframe(
...     [(1, True), (2, False), (3, None)], schema=["id", "approved"])
>>> df.select(
...     "id", iff(df["approved"], lit("ship"), lit("hold")).alias("action")
... ).sort("id").collect()
[Row(ID=1, ACTION='ship'), Row(ID=2, ACTION='hold'), Row(ID=3, ACTION='hold')]

Only an approved row selects "ship". Both false and unknown (NULL) approval select "hold".