You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/UserGuide/Master/Table/SQL-Manual/Select-Clause.md
+122Lines changed: 122 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,7 @@ setQuantifier
41
41
42
42
- It supports aggregate functions (e.g., `SUM`, `AVG`, `COUNT`) and window functions, logically executed last in the query process.
43
43
- DISTINCT Keyword: `SELECT DISTINCT column_name` ensures that the values in the query results are unique, removing duplicates.
44
+
- COLUMNS Function: The COLUMNS function is supported in the SELECT clause for column filtering. It can be combined with expressions, allowing the expression's logic to apply to all columns selected by the function.
44
45
45
46
## 2. Detailed Syntax:
46
47
@@ -58,6 +59,17 @@ Usage scenarios for DISTINCT:
58
59
59
60
3.**AGROUP BY Clause**: Use ALL and DISTINCT quantifiers in the GROUP BY clause to determine whether each duplicate grouping set produces distinct output rows.
60
61
62
+
`COLUMNS` Function:
63
+
64
+
1.**`COLUMNS(*)`**: Matches all columns and supports combining with expressions.
65
+
2.**`COLUMNS(regexStr) ? AS identifier`**: Regular expression matching
66
+
- Selects columns whose names match the specified regular expression `(regexStr)` and supports combining with expressions.
67
+
- Allows renaming columns by referencing groups captured by the regular expression. If `AS` is omitted, the original column name is displayed in the format `_coln_original_name` (where `n` is the column’s position in the result table).
68
+
- Renaming Syntax:
69
+
- Use parentheses () in regexStr to define capture groups.
70
+
- Reference captured groups in identifier using `'$index'`.
71
+
- Note: The identifier must be enclosed in double quotes if it contains special characters like `$`.
72
+
61
73
## 3. Example Data
62
74
63
75
@@ -262,6 +274,116 @@ Total line number = 18
262
274
It costs 0.189s
263
275
```
264
276
277
+
### 3.2 Colums Function
278
+
279
+
1. Without combining expressions
280
+
```sql
281
+
-- Query data from columns whose names start with 'm'
282
+
IoTDB:database1>select columns('^m.*') from table1 limit5
283
+
+--------+-----------+
284
+
|model_id|maintenance|
285
+
+--------+-----------+
286
+
| E| 180|
287
+
| E| 180|
288
+
| C| 90|
289
+
| C| 90|
290
+
| C| 90|
291
+
+--------+-----------+
292
+
293
+
294
+
-- Query columns whose names start with 'o' - throw an exception if no columns match
295
+
IoTDB:database1>select columns('^o.*') from table1 limit5
296
+
Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: No matching columns found that match regex '^o.*'
297
+
298
+
299
+
-- Query data from columns whose names start with 'm' and rename them with 'series_' prefix
Copy file name to clipboardExpand all lines: src/UserGuide/latest-Table/SQL-Manual/Select-Clause.md
+123-1Lines changed: 123 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@
21
21
22
22
# SELECT Clauses
23
23
24
-
**SELECT Clause** specifies the columns included in the query results.
24
+
**SELECT Clause** specifies the columns included in the query results.
25
25
26
26
## 1. Syntax Overview
27
27
@@ -41,6 +41,7 @@ setQuantifier
41
41
42
42
- It supports aggregate functions (e.g., `SUM`, `AVG`, `COUNT`) and window functions, logically executed last in the query process.
43
43
- DISTINCT Keyword: `SELECT DISTINCT column_name` ensures that the values in the query results are unique, removing duplicates.
44
+
- COLUMNS Function: The COLUMNS function is supported in the SELECT clause for column filtering. It can be combined with expressions, allowing the expression's logic to apply to all columns selected by the function.
44
45
45
46
## 2. Detailed Syntax:
46
47
@@ -58,6 +59,17 @@ Usage scenarios for DISTINCT:
58
59
59
60
3.**AGROUP BY Clause**: Use ALL and DISTINCT quantifiers in the GROUP BY clause to determine whether each duplicate grouping set produces distinct output rows.
60
61
62
+
`COLUMNS` Function:
63
+
64
+
1.**`COLUMNS(*)`**: Matches all columns and supports combining with expressions.
65
+
2.**`COLUMNS(regexStr) ? AS identifier`**: Regular expression matching
66
+
- Selects columns whose names match the specified regular expression `(regexStr)` and supports combining with expressions.
67
+
- Allows renaming columns by referencing groups captured by the regular expression. If `AS` is omitted, the original column name is displayed in the format `_coln_original_name` (where `n` is the column’s position in the result table).
68
+
- Renaming Syntax:
69
+
- Use parentheses () in regexStr to define capture groups.
70
+
- Reference captured groups in identifier using `'$index'`.
71
+
- Note: The identifier must be enclosed in double quotes if it contains special characters like `$`.
72
+
61
73
## 3. Example Data
62
74
63
75
@@ -262,6 +274,116 @@ Total line number = 18
262
274
It costs 0.189s
263
275
```
264
276
277
+
### 3.2 Colums Function
278
+
279
+
1. Without combining expressions
280
+
```sql
281
+
-- Query data from columns whose names start with 'm'
282
+
IoTDB:database1>select columns('^m.*') from table1 limit5
283
+
+--------+-----------+
284
+
|model_id|maintenance|
285
+
+--------+-----------+
286
+
| E| 180|
287
+
| E| 180|
288
+
| C| 90|
289
+
| C| 90|
290
+
| C| 90|
291
+
+--------+-----------+
292
+
293
+
294
+
-- Query columns whose names start with 'o' - throw an exception if no columns match
295
+
IoTDB:database1>select columns('^o.*') from table1 limit5
296
+
Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: No matching columns found that match regex '^o.*'
297
+
298
+
299
+
-- Query data from columns whose names start with 'm' and rename them with 'series_' prefix
0 commit comments