IFNULL

Returns the value of its first argument if it is not NULL, otherwise returns the value of its second argument.

This function corresponds to the ifnull(X, Y) function in SQLite. It is a two-argument variant of the COALESCE function. ifnull(X, Y) is equivalent to coalesce(X, Y).

This is commonly used to provide a default value for a potentially NULL column.

Example

// If `middleName` is NULL, use an empty string instead.
val fullName = select(Users.firstName CONCAT " " CONCAT IFNULL(Users.middleName, StringLiteral("")) CONCAT " " CONCAT Users.lastName)
.from(Users)

// Use a backup phone number if the primary one is NULL.
val contactNumber = select(IFNULL(Users.primaryPhone, Users.secondaryPhone))
.from(Users)

Return

A KQLiteColumn with the same type T as the input columns, containing the result of the IFNULL operation.

Author

MOHAMMAD AZIM ANSARI

Parameters

x

The first column or value to check. This value is returned if it is not NULL.

y

The second column or value to return if x is NULL. Its type must be a subtype of T.

Type Parameters

T

The underlying data type of the columns.

See also