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] (https://github.com/snowflakedb/snowpark-python/blob/v1.26.0/snowpark-python/src/snowflake/snowpark/functions.py#L7963-L7989)¶
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 ifcondition
is true.expr2 – A
Column
expression or a literal value, which will be returned ifcondition
is false.
Examples:
>>> df = session.create_dataframe([True, False, None], schema=["a"]) >>> df.select(iff(df["a"], lit("true"), lit("false")).alias("iff")).collect() [Row(IFF='true'), Row(IFF='false'), Row(IFF='false')]