Skip to main content


About 3 min


Users can delete data that meet the deletion condition in the specified timeseries by using the DELETE statement. When deleting data, users can select one or more timeseries paths, prefix paths, or paths with star to delete data within a certain time interval.

In a JAVA programming environment, you can use the Java JDBC to execute single or batch UPDATE statements.

Delete Single Timeseries

Taking ln Group as an example, there exists such a usage scenario:

The wf02 plant's wt02 device has many segments of errors in its power supply status before 2017-11-01 16:26:00, and the data cannot be analyzed correctly. The erroneous data affected the correlation analysis with other devices. At this point, the data before this time point needs to be deleted. The SQL statement for this operation is

delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00;

In case we hope to merely delete the data before 2017-11-01 16:26:00 in the year of 2017, The SQL statement is:

delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00;

IoTDB supports to delete a range of timeseries points. Users can write SQL expressions as follows to specify the delete interval:

delete from root.ln.wf02.wt02.status where time < 10
delete from root.ln.wf02.wt02.status where time <= 10
delete from root.ln.wf02.wt02.status where time < 20 and time > 10
delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10
delete from root.ln.wf02.wt02.status where time > 20
delete from root.ln.wf02.wt02.status where time >= 20
delete from root.ln.wf02.wt02.status where time = 20

Please pay attention that multiple intervals connected by "OR" expression are not supported in delete statement:

delete from root.ln.wf02.wt02.status where time > 4 or time < 0
Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic
expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND'

If no "where" clause specified in a delete statement, all the data in a timeseries will be deleted.

delete from root.ln.wf02.wt02.status

Delete Multiple Timeseries

If both the power supply status and hardware version of the ln group wf02 plant wt02 device before 2017-11-01 16:26:00 need to be deleted, the prefix path with broader meaning or the path with star can be used to delete the data. The SQL statement for this operation is:

delete from root.ln.wf02.wt02 where time <= 2017-11-01T16:26:00;


delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00;

It should be noted that when the deleted path does not exist, IoTDB will not prompt that the path does not exist, but that the execution is successful, because SQL is a declarative programming method. Unless it is a syntax error, insufficient permissions and so on, it is not considered an error, as shown below:

IoTDB> delete from root.ln.wf03.wt02.status where time < now()
Msg: The statement is executed successfully.

Delete Time Partition (experimental)

You may delete all data in a time partition of a database using the following grammar:

DELETE PARTITION root.ln 0,1,2

The 0,1,2 above is the id of the partition that is to be deleted, you can find it from the IoTDB
data folders or convert a timestamp manually to an id using timestamp / partitionInterval (flooring), and the partitionInterval should be in your config (if time-partitioning is
supported in your version).

Please notice that this function is experimental and mainly for development, please use it with care.

Time-to-live (TTL)

IoTDB supports storage-level TTL settings, which means it is able to delete old data automatically and periodically. The benefit of using TTL is that hopefully you can control the total disk space usage and prevent the machine from running out of disks. Moreover, the query performance may downgrade as the total number of files goes up and the memory usage also increase as there are more files. Timely removing such files helps to keep at a high query performance level and reduce memory usage.

The default unit of TTL is milliseconds. If the time precision in the configuration file changes to another, the TTL is still set to milliseconds.


The SQL Statement for setting TTL is as follow:

IoTDB> set ttl to root.ln 3600000

This example means that for data in root.ln, only 3600000 ms, that is, the latest 1 hour will remain, the older one is removed or made invisible.

IoTDB> set ttl to root.sgcc.** 3600000

It supports setting TTL for databases in a path. This example represents setting TTL for all databases in the root.sgcc path.

IoTDB> set ttl to root.** 3600000

This example represents setting TTL for all databases.

Unset TTL

To unset TTL, we can use follwing SQL statement:

IoTDB> unset ttl to root.ln

After unset TTL, all data will be accepted in root.ln.

IoTDB> unset ttl to root.sgcc.**

Unset the TTL setting for all databases in the root.sgcc path.

IoTDB> unset ttl to root.**

Unset the TTL setting for all databases.

Show TTL

To Show TTL, we can use following SQL statement:

IoTDB> SHOW TTL ON StorageGroupNames

The SHOW ALL TTL example gives the TTL for all databases.
The SHOW TTL ON root.ln,root.sgcc,root.DB example shows the TTL for the three storage
groups specified.
Note: the TTL for databases that do not have a TTL set will display as null.

IoTDB> show all ttl
| database|ttl(ms)|
|  root.ln|3600000|
|root.sgcc|   null|
|  root.DB|3600000|

Copyright © 2024 The Apache Software Foundation.
Apache and the Apache feather logo are trademarks of The Apache Software Foundation

Have a question? Connect with us on QQ, WeChat, or Slack. Join the community now.

We use Google Analytics to collect anonymous, aggregated usage information.