Delete Data
January 3, 2025About 2 min
Delete Data
1. Data Deletion
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.
1.1 Syntax Overview
DELETE FROM <TABLE_NAME> [WHERE_CLAUSE]?
WHERE_CLAUSE:
WHERE DELETE_CONDITION
DELETE_CONDITION:
SINGLE_CONDITION
| DELETE_CONDITION AND DELETE_CONDITION
| DELETE_CONDITION OR DELETE_CONDITION
SINGLE_CODITION:
TIME_CONDITION | ID_CONDITION
TIME_CONDITION:
time TIME_OPERATOR LONG_LITERAL
TIME_OPERATOR:
< | > | <= | >= | =
ID_CONDITION:
identifier = STRING_LITERALNote:
- The
DELETE_CONDITIONcan include single conditions or be a combination of conditions (logical operators likeANDandORare used). Currently, only time conditions and tag conditions are supported. - For time conditions, operators include standard comparison symbols (
<,>, etc.). - For tag conditions, only equality (=) is allowed.
1.2 Examples
The Example Data pagepage 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.
1.2.1 Delet All Data from a Table
# Whole table deletion
DELETE FROM table11.2.2 Delete Data within a Specific Time Range
# Single time interval deletion
DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00
# Multi time interval deletion
DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:001.2.3 Deleting Data for a Specific Device
# Device-specific deletion
# Identifier conditions only support the '=' operator
DELETE FROM table1 WHERE device_id='101' and model_id = 'B'
# Device-specific deletion with time interval
DELETE FROM table1
WHERE time >= 2024-11-27 16:39:00 and time <= 2024-11-29 16:42:00
AND device_id='101' and model_id = 'B'
# Device-type-specific deletion
DELETE FROM table1 WHERE model_id = 'B'2. Device Deletion
The device deletion statement supports deleting all devices and their related data in the table.
2.1 Syntax Overview
DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)?Notes:
- The
WHEREclause supports only equality filters on tags. Conditions can be combined usingANDandORoperators. - Time conditions are not supported in the
DELETE DEVICESstatement.
2.2 Example
DELETE DEVICES FROM table1 WHERE device_id = '101'