You are viewing documentation about an older version (1.12.1). View latest version

snowflake.snowpark.functions.coalesce

snowflake.snowpark.functions.coalesce(*e: Union[Column, str]) Column[source]

Returns the first non-NULL expression among its arguments, or NULL if all its arguments are NULL.

Example:

>>> df = session.create_dataframe([[1, 2, 3], [None, 2, 3], [None, None, 3], [None, None, None]], schema=['a', 'b', 'c'])
>>> df.select(df.a, df.b, df.c, coalesce(df.a, df.b, df.c).as_("COALESCE")).show()
-----------------------------------
|"A"   |"B"   |"C"   |"COALESCE"  |
-----------------------------------
|1     |2     |3     |1           |
|NULL  |2     |3     |2           |
|NULL  |NULL  |3     |3           |
|NULL  |NULL  |NULL  |NULL        |
-----------------------------------
Copy