snowflake.snowpark.functions.nvl2¶

snowflake.snowpark.functions.nvl2(expr1: Union[snowflake.snowpark.column.Column, str], expr2: Union[snowflake.snowpark.column.Column, str], expr3: Union[snowflake.snowpark.column.Column, str]) → Column[source]¶

Returns expr2 if expr1 is not None, otherwise returns expr3.

Parameters:
  • expr1 (ColumnOrName) – The expression to test for None.

  • expr2 (ColumnOrName) – The value to return if expr1 is not None.

  • expr3 (ColumnOrName) – The value to return if expr1 is None.

Returns:

The result of the nvl2 function.

Return type:

Column

Example:

>>> from snowflake.snowpark.functions import col
>>> df = session.create_dataframe([
...     [0, 5, 3],
...     [0, 5, None],
...     [0, None, 3],
...     [None, 5, 3],
...     [None, None, 3]
... ], schema=["a", "b", "c"])
>>> df.select(nvl2(col("a"), col("b"), col("c")).alias("nvl2_result")).collect()
[Row(NVL2_RESULT=5), Row(NVL2_RESULT=5), Row(NVL2_RESULT=None), Row(NVL2_RESULT=3), Row(NVL2_RESULT=3)]
Copy