Skip to content

Commit a1cc5a6

Browse files
committed
Table model data query and data deletion in English
1 parent 868793d commit a1cc5a6

10 files changed

Lines changed: 1088 additions & 12 deletions

File tree

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<!--
2+
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
20+
-->
21+
22+
# Data Deletion
23+
24+
## 1. Data Deletion
25+
26+
Data deletion in IoTDB can be achieved using the DELETE statement. You can specify filters based on tags and time to delete specific subsets of data.
27+
28+
### 1.1 Syntax Overview
29+
30+
```SQL
31+
DELETE FROM <TABLE_NAME> [WHERE_CLAUSE]?
32+
33+
WHERE_CLAUSE:
34+
WHERE DELETE_CONDITION
35+
36+
DELETE_CONDITION:
37+
SINGLE_CONDITION
38+
| DELETE_CONDITION AND DELETE_CONDITION
39+
| DELETE_CONDITION OR DELETE_CONDITION
40+
41+
SINGLE_CODITION:
42+
TIME_CONDITION | ID_CONDITION
43+
44+
TIME_CONDITION:
45+
time TIME_OPERATOR LONG_LITERAL
46+
47+
TIME_OPERATOR:
48+
< | > | <= | >= | =
49+
50+
ID_CONDITION:
51+
identifier = STRING_LITERAL
52+
```
53+
54+
**Note:**
55+
56+
- The `DELETE_CONDITION` can include single conditions or be a combination of conditions (logical operators like `AND` and `OR` are used). Currently, only **time conditions** and **tag conditions** are supported.
57+
- For **time conditions**, operators include standard comparison symbols (`<`, `>`, etc.).
58+
- For **tag conditions**, only equality (=) is allowed.
59+
60+
### 1.2 Examples
61+
62+
The [Sample-Data](../Reference/Sample-Data.md)page provides SQL statements to construct table schemas and insert data. By downloading and executing these statements in the IoTDB CLI, you can import the data into IoTDB. This data can be used to test and run the example SQL queries included in this documentation, allowing you to reproduce the described results.
63+
64+
#### 1.2.1 Delet All Data from a Table
65+
66+
```SQL
67+
# Whole table deletion
68+
DELETE FROM table1
69+
```
70+
71+
#### 1.2.2 Delete Data within a Specific Time Range
72+
73+
```SQL
74+
# Single time interval deletion
75+
DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00
76+
77+
# Multi time interval deletion
78+
DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00
79+
```
80+
81+
#### 1.2.3 Deleting Data for a Specific Device
82+
83+
```SQL
84+
# Device-specific deletion
85+
# Identifier conditions only support the '=' operator
86+
DELETE FROM table1 WHERE device_id='101' and model_id = 'B'
87+
88+
# Device-specific deletion with time interval
89+
DELETE FROM table1
90+
WHERE time >= 2024-11-27 16:39:00 and time <= 2024-11-29 16:42:00
91+
AND device_id='101' and model_id = 'B'
92+
93+
# Device-type-specific deletion
94+
DELETE FROM table1 WHERE model_id = 'B'
95+
```
96+
97+
## 2. Device Deletion
98+
99+
When a device is written to IoTDB, its metadata is retained even if data is deleted. To remove both the data and metadata of a device, you can use the `DELETE DEVICES` statement.
100+
101+
### 2.1 Syntax Overview
102+
103+
```SQL
104+
DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)?
105+
```
106+
107+
**Notes:**
108+
109+
- The `WHERE` clause supports only equality filters on tags. Conditions can be combined using `AND` and `OR` operators.
110+
- Time conditions are **not** supported in the `DELETE DEVICES` statement.
111+
112+
### 2.2 Example
113+
114+
```SQL
115+
DELETE DEVICES FROM table1 WHERE device_id = '101'
116+
```

0 commit comments

Comments
 (0)