1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- [role="xpack"]
- [testenv="basic"]
- [[sql-functions-conditional]]
- === Conditional Functions
- Functions that return one of their arguments by evaluating in an if-else manner.
- [[sql-functions-conditional-coalesce]]
- ==== `COALESCE`
- .Synopsis
- [source, sql]
- ----
- COALESCE ( expression<1>, expression<2>, ... )
- ----
- *Input*:
- <1> 1st expression
- <2> 2nd expression
- ...
- **N**th expression
- COALESCE can take an arbitrary number of arguments.
- *Output*: one of the expressions or `null`
- .Description
- Returns the first of its arguments that is not null.
- If all arguments are null, then it returns `null`.
- ["source","sql",subs="attributes,callouts,macros"]
- ----
- include-tagged::{sql-specs}/docs.csv-spec[coalesceReturnNonNull]
- ----
- ["source","sql",subs="attributes,callouts,macros"]
- ----
- include-tagged::{sql-specs}/docs.csv-spec[coalesceReturnNull]
- ----
- [[sql-functions-conditional-ifnull]]
- ==== `IFNULL`
- .Synopsis
- [source, sql]
- ----
- IFNULL ( expression<1>, expression<2> )
- ----
- *Input*:
- <1> 1st expression
- <2> 2nd expression
- *Output*: 2nd expression if 1st expression is null, otherwise 1st expression.
- .Description
- Variant of <<sql-functions-conditional-coalesce>> with only two arguments.
- Returns the first of its arguments that is not null.
- If all arguments are null, then it returns `null`.
- ["source","sql",subs="attributes,callouts,macros"]
- ----
- include-tagged::{sql-specs}/docs.csv-spec[ifNullReturnFirst]
- ----
- ["source","sql",subs="attributes,callouts,macros"]
- ----
- include-tagged::{sql-specs}/docs.csv-spec[ifNullReturnSecond]
- ----
|