Skip to main content

nvl

Returns col2 if col1 is null, or col1 otherwise.

For the corresponding Databricks SQL function, see nvl function.

Syntax

Python
from pyspark.databricks.sql import functions as dbf

dbf.nvl(col1=<col1>, col2=<col2>)

Parameters

Parameter

Type

Description

col1

pyspark.sql.Column or str

The first column to check.

col2

pyspark.sql.Column or str

The value to return if col1 is null.

Examples

Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(None, 8,), (1, 9,)], ["a", "b"])
df.select('*', dbf.nvl(df.a, df.b)).show()
Output
+----+---+--------+
| a| b|nvl(a, b)|
+----+---+--------+
|NULL| 8| 8|
| 1| 9| 1|
+----+---+--------+