2023-10-17 23:36:14 +08:00
|
|
|
[discrete]
|
2023-05-11 23:02:27 +08:00
|
|
|
[[esql-case]]
|
|
|
|
=== `CASE`
|
|
|
|
|
2023-10-17 23:36:14 +08:00
|
|
|
*Syntax*
|
|
|
|
|
|
|
|
[source,txt]
|
|
|
|
----
|
|
|
|
CASE(condition1, value1[, ..., conditionN, valueN][, default_value])
|
|
|
|
----
|
|
|
|
|
|
|
|
*Parameters*
|
|
|
|
|
|
|
|
`conditionX`::
|
|
|
|
A condition.
|
|
|
|
|
|
|
|
`valueX`::
|
|
|
|
The value that's returned when the corresponding condition is the first to
|
|
|
|
evaluate to `true`.
|
|
|
|
|
|
|
|
`default_value`::
|
|
|
|
The default value that's is returned when no condition matches.
|
|
|
|
|
|
|
|
*Description*
|
|
|
|
|
2023-05-11 23:02:27 +08:00
|
|
|
Accepts pairs of conditions and values. The function returns the value that
|
2023-10-17 23:36:14 +08:00
|
|
|
belongs to the first condition that evaluates to `true`.
|
|
|
|
|
|
|
|
If the number of arguments is odd, the last argument is the default value which
|
|
|
|
is returned when no condition matches.
|
|
|
|
|
|
|
|
*Example*
|
2023-05-11 23:02:27 +08:00
|
|
|
|
|
|
|
[source,esql]
|
2023-10-17 23:36:14 +08:00
|
|
|
[source.merge.styled,esql]
|
2023-05-11 23:02:27 +08:00
|
|
|
----
|
2023-10-17 23:36:14 +08:00
|
|
|
include::{esql-specs}/docs.csv-spec[tag=case]
|
2023-05-11 23:02:27 +08:00
|
|
|
----
|
2023-10-17 23:36:14 +08:00
|
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|
|
|===
|
|
|
|
include::{esql-specs}/docs.csv-spec[tag=case-result]
|
|
|
|
|===
|