snowflake.snowpark.CaseExpr¶
- class snowflake.snowpark.CaseExpr(expr: CaseWhen)[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/column.py#L773-L827)¶
Bases:
Column
Represents a CASE expression.
To construct this object for a CASE expression, call the
functions.when()
specifying a condition and the corresponding result for that condition. Then, callwhen()
andotherwise()
methods to specify additional conditions and results.Examples:
>>> from snowflake.snowpark.functions import when, col, lit >>> df = session.create_dataframe([[None], [1], [2]], schema=["a"]) >>> df.select(when(col("a").is_null(), lit(1)) \ ... .when(col("a") == 1, lit(2)) \ ... .otherwise(lit(3)).alias("case_when_column")).collect() [Row(CASE_WHEN_COLUMN=1), Row(CASE_WHEN_COLUMN=2), Row(CASE_WHEN_COLUMN=3)]
Methods
else_
(value)Sets the default result for this CASE expression.
otherwise
(value)Sets the default result for this CASE expression.
when
(condition, value)Appends one more WHEN condition to the CASE expression.