elasticsearch/docs/reference/esql/functions/case.asciidoc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
865 B
Plaintext
Raw Normal View History

[discrete]
2023-05-11 23:02:27 +08:00
[[esql-case]]
=== `CASE`
*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
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]
[source.merge.styled,esql]
2023-05-11 23:02:27 +08:00
----
include::{esql-specs}/docs.csv-spec[tag=case]
2023-05-11 23:02:27 +08:00
----
[%header.monospaced.styled,format=dsv,separator=|]
|===
include::{esql-specs}/docs.csv-spec[tag=case-result]
|===