浏览代码

Add CASE function

Abdon Pijpelink 2 年之前
父节点
当前提交
09a1324a14
共有 1 个文件被更改,包括 19 次插入0 次删除
  1. 19 0
      docs/reference/esql/esql-functions.asciidoc

+ 19 - 0
docs/reference/esql/esql-functions.asciidoc

@@ -5,6 +5,7 @@
 these functions:
 
 * <<esql-abs>>
+* <<esql-case>>
 * <<esql-concat>>
 * <<esql-date_format>>
 * <<esql-date_trunc>>
@@ -25,6 +26,24 @@ FROM employees
 | EVAL abs_height = ABS(0.0 - height)
 ----
 
+[[esql-case]]
+=== `CASE`
+
+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.
+
+[source,esql]
+----
+FROM employees
+| EVAL type = CASE(
+    languages <= 1, "monolingual",
+    languages <= 2, "bilingual",
+     "polyglot")
+| PROJECT first_name, last_name, type
+----
+
 [[esql-concat]]
 === `CONCAT`
 Concatenates two or more strings.