Skip to content

Commit 2f19570

Browse files
Marios Trivyzasmatriv
authored andcommitted
SQL: [docs] Add documentation for COALESCE (#35740)
Follows: #35253
1 parent 87cb628 commit 2f19570

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[role="xpack"]
2+
[testenv="basic"]
3+
[[sql-functions-conditional]]
4+
=== Conditional Functions
5+
6+
Functions that return one of their arguments by evaluating in an if-else manner.
7+
8+
[[sql-functions-conditional-coalesce]]
9+
==== `COALESCE`
10+
11+
.Synopsis
12+
[source, sql]
13+
----
14+
COALESCE ( expression<1>, expression<2>, ... )
15+
----
16+
17+
*Input*:
18+
19+
<1> 1st expression
20+
21+
<2> 2nd expression
22+
23+
...
24+
25+
**N**th expression
26+
27+
COALESCE can take an arbitrary number of arguments.
28+
29+
*Output*: one of the expressions or `null`
30+
31+
.Description
32+
33+
Returns the first of its arguments that is not null.
34+
If all arguments are null, then it returns `null`.
35+
36+
37+
38+
["source","sql",subs="attributes,callouts,macros"]
39+
----
40+
include-tagged::{sql-specs}/docs.csv-spec[coalesceReturnNonNull]
41+
----
42+
43+
["source","sql",subs="attributes,callouts,macros"]
44+
----
45+
include-tagged::{sql-specs}/docs.csv-spec[coalesceReturnNull]
46+
----

docs/reference/sql/functions/index.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* <<sql-functions-math, Mathematical>>
1313
* <<sql-functions-string, String>>
1414
* <<sql-functions-type-conversion,Type Conversion>>
15+
* <<sql-functions-conditional, Conditional>>
1516

1617
include::operators.asciidoc[]
1718
include::aggs.asciidoc[]
@@ -20,3 +21,4 @@ include::search.asciidoc[]
2021
include::math.asciidoc[]
2122
include::string.asciidoc[]
2223
include::type-conversion.asciidoc[]
24+
include::conditional.asciidoc[]

x-pack/plugin/sql/qa/src/main/resources/docs.csv-spec

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,3 +1510,24 @@ SELECT TRUNCATE(-345.153, 1) AS trimmed;
15101510
// end::mathTruncateWithPositiveParameter
15111511
;
15121512

1513+
1514+
coalesceReturnNonNull
1515+
// tag::coalesceReturnNonNull
1516+
SELECT COALESCE(null, 'elastic', 'search') AS "coalesce";
1517+
1518+
coalesce
1519+
---------------
1520+
elastic
1521+
// end::coalesceReturnNonNull
1522+
;
1523+
1524+
1525+
coalesceReturnNull
1526+
// tag::coalesceReturnNull
1527+
SELECT COALESCE(null, null, null, null) AS "coalesce";
1528+
1529+
coalesce
1530+
---------------
1531+
null
1532+
// end::coalesceReturnNull
1533+
;

0 commit comments

Comments
 (0)