Coalesce
Builds a coalesce(...) expression, usable anywhere an SQL element is accepted (typically as a
Select column).
Constructor
Coalesce(...expressions: any[]): Coalesce
new Coalesce(...expressions: any[]): Coalesce
Dual-callable. Each argument is converted through the active SerializeContext (so strings,
literals, Field, Raw, Param, and sub-Select are all accepted).
import { Coalesce, Select } from '@sqb/builder';
Select(Coalesce('nick_name', 'given_name', "'Unnamed'")).from('customers');
// select coalesce(nick_name, given_name, 'Unnamed') from customers
An empty argument list serializes to an empty string (Coalesce() contributes nothing to its
parent expression).
Properties
| Key | Type | Readonly | Description |
|---|---|---|---|
_type | SerializationType.COALESCE_STATEMENT | Yes | Discriminates this node during serialization. |
_expressions | any[] | No | The arguments passed to the constructor, in order. |
_alias | string | undefined | No | Set by .as(). |
Methods
as()
as(alias: string): this
Sets an alias, rendered as a trailing alias after the closing paren (no AS keyword).
Coalesce('nick_name', 'given_name').as('name');
// coalesce(nick_name, given_name) name