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

snowflake.snowpark.functions.coalesce

snowflake.snowpark.functions.coalesce(*e: Union[Column, str]) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/functions.py#L1426-L1445)

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
Language: English