Skip to content

Type Method

coalesce(_:)

A factory method to simplify use of the standard COALESCE() function.
static func coalesce(_ expressions: [any SQLExpression]) -> SQLFunction

Parameters

expressions

A list of expressions to coalesce.

Return Value

An appropriately-constructed SQLFunction.

Discussion

The SQL COALESCE() function takes one or more arguments, and returns the first such arguments which passes an IS NOT NULL test. If all arguments evaluate to NULL, NULL is returned.

Example:

try await database.select()
    .column(SQLFunction.coalesce(SQLColumn("col1"), SQLBind(defaultValue)))
    .all()