Ver código fonte

doc(sql): support case expression

ngjaying 4 anos atrás
pai
commit
81ca39c5f9

+ 1 - 1
docs/en_US/sqls/lexical_elements.md

@@ -31,7 +31,7 @@ SELECT `a-b`, `hello world`, `中文Chinese` from demo
 **Reserved keywords for rule SQL**: If you'd like to use the following keyword in rule SQL, you will have to use backtick to enclose them.
 **Reserved keywords for rule SQL**: If you'd like to use the following keyword in rule SQL, you will have to use backtick to enclose them.
 
 
 ```
 ```
-SELECT, FROM, JOIN, LEFT, INNER, ON, WHERE, GROUP, ORDER, HAVING, BY, ASC, DESC, AND, OR
+SELECT, FROM, JOIN, LEFT, INNER, ON, WHERE, GROUP, ORDER, HAVING, BY, ASC, DESC, AND, OR, CASE, WHEN, THEN, ELSE, END
 ```
 ```
 
 
 The following is an example for using a stream named `from`, which is a reserved keyword in Kuiper.
 The following is an example for using a stream named `from`, which is a reserved keyword in Kuiper.

+ 51 - 0
docs/en_US/sqls/query_language_elements.md

@@ -303,7 +303,58 @@ FROM table_name
 ORDER BY column1, column2, ... ASC|DESC;
 ORDER BY column1, column2, ... ASC|DESC;
 ```
 ```
 
 
+## Case Expression
 
 
+The case expression evaluates a list of conditions and returns one of multiple possible result expressions. It let you use IF ... THEN ... ELSE logic in SQL statements without having to invoke procedures.
+
+There are two types of case expression: simple case expression and searched case expression.
+
+### Simple Case Expression
+
+The simple case expression compares an expression to a set of simple expressions to determine the result.
+
+#### Syntax
+
+```sql
+CASE value   
+     WHEN conditionValue THEN result_expression [ ...n ]   
+     [ ELSE else_result_expression ]   
+END   
+```
+
+**Example**:
+
+```sql
+SELECT CASE color 
+    WHEN "red" THEN 1 
+    WHEN "yellow" THEN 2 
+    ELSE 3 END as colorInteger, 
+humidity FROM tbl
+```
+
+### Searched Case Expression
+
+The searched case expression evaluates a set of bool expressions to determine the result.
+
+#### Syntax
+
+```sql
+CASE    
+     WHEN condition THEN result_expression [ ...n ]   
+     [ ELSE else_result_expression ]   
+END 
+```
+
+**Example**:
+
+```sql
+SELECT CASE 
+    WHEN size < 150 THEN "S" 
+    WHEN size < 170 THEN "M"
+    WHEN size < 175 THEN "L"
+    ELSE "XL" END as sizeLabel
+FROM tbl
+```
 
 
 ## Use reserved keywords or special characters
 ## Use reserved keywords or special characters
 
 

+ 1 - 1
docs/zh_CN/sqls/lexical_elements.md

@@ -31,7 +31,7 @@ SELECT `a-b`, `hello world`, `中文Chinese` from demo
 **规则 SQL 的保留关键字**:如果您想在规则 SQL 中使用以下关键字,则必须使用反撇号将其括起来。
 **规则 SQL 的保留关键字**:如果您想在规则 SQL 中使用以下关键字,则必须使用反撇号将其括起来。
 
 
 ```
 ```
-SELECT, FROM, JOIN, LEFT, INNER, ON, WHERE, GROUP, ORDER, HAVING, BY, ASC, DESC, AND, OR
+SELECT, FROM, JOIN, LEFT, INNER, ON, WHERE, GROUP, ORDER, HAVING, BY, ASC, DESC, AND, OR, CASE, WHEN, THEN, ELSE, END
 ```
 ```
 
 
 以下是使用名为 `from` 的流的示例,`from` 是 Kuiper 中的保留关键字。
 以下是使用名为 `from` 的流的示例,`from` 是 Kuiper 中的保留关键字。

+ 53 - 0
docs/zh_CN/sqls/query_language_elements.md

@@ -303,6 +303,59 @@ FROM table_name
 ORDER BY column1, column2, ... ASC|DESC;
 ORDER BY column1, column2, ... ASC|DESC;
 ```
 ```
 
 
+## Case Expression
+
+The case expression evaluates a list of conditions and returns one of multiple possible result expressions. It let you use IF ... THEN ... ELSE logic in SQL statements without having to invoke procedures.
+
+There are two types of case expression: simple case expression and searched case expression.
+
+### Simple Case Expression
+
+The simple case expression compares an expression to a set of simple expressions to determine the result.
+
+#### Syntax
+
+```sql
+CASE value   
+     WHEN conditionValue THEN result_expression [ ...n ]   
+     [ ELSE else_result_expression ]   
+END   
+```
+
+**Example**:
+
+```sql
+SELECT CASE color 
+    WHEN "red" THEN 1 
+    WHEN "yellow" THEN 2 
+    ELSE 3 END as colorInteger, 
+humidity FROM tbl
+```
+
+### Searched Case Expression
+
+The searched case expression evaluates a set of bool expressions to determine the result.
+
+#### Syntax
+
+```sql
+CASE    
+     WHEN condition THEN result_expression [ ...n ]   
+     [ ELSE else_result_expression ]   
+END 
+```
+
+**Example**:
+
+```sql
+SELECT CASE 
+    WHEN size < 150 THEN "S" 
+    WHEN size < 170 THEN "M"
+    WHEN size < 175 THEN "L"
+    ELSE "XL" END as sizeLabel
+FROM tbl
+```
+
 ## 使用保留字或特殊字符
 ## 使用保留字或特殊字符
 如果你想在 SQL 或者流管理中使用保留关键字,或者特殊字符,请参考 [Kuiper 词法元素](lexical_elements.md).
 如果你想在 SQL 或者流管理中使用保留关键字,或者特殊字符,请参考 [Kuiper 词法元素](lexical_elements.md).