Loading...

verticapy.sql.functions.coalesce#

verticapy.sql.functions.coalesce(expr: str | list[str] | StringSQL | list[StringSQL], *args) StringSQL#

Returns the value of the first non-null expression in the list.

Parameters#

expr: SQLExpression

Expression.

args: SQLExpression

A number of expressions.

Returns#

StringSQL

SQL string.

Examples#

First, let’s import the vDataFrame in order to create a dummy dataset.

from verticapy import vDataFrame

Now, let’s import the VerticaPy SQL functions.

import verticapy.sql.functions as vpf

We can now build a dummy dataset.

df = vDataFrame({"x": [0.8, -1, None, -2, None]})

Now, let’s go ahead and apply the function.

df["coalesce_x"] = vpf.coalesce(df["x"], 777)
display(df)
123
x
Numeric(21)
60%
123
coalesce_x
Numeric(21)
100%
10.80.8
2-1.0-1.0
3[null]777.0
4-2.0-2.0
5[null]777.0

Note

It’s crucial to utilize VerticaPy SQL functions in coding, as they can be updated over time with new syntax. While SQL functions typically remain stable, they may vary across platforms or versions. VerticaPy effectively manages these changes, a task not achievable with pure SQL.

See also

vDataFrame.eval() : Evaluates the expression.