Deleting Data in InfluxDB
When working with InfluxDB, you may find the need to delete specific data points. However, it's important to understand the constraints of the delete command, particularly regarding the use of the WHERE clause.
Basic Delete Command
The simplest form of a delete command in InfluxDB is as follows:
DELETE FROM <measurement> WHERE time < now() - 1h;
This command will remove all entries from the specified measurement that are older than one hour.
Common Issues with Delete Queries
One common issue users encounter is the error message: "Delete queries can't have a WHERE clause that doesn't reference time." This means that you cannot use fields other than time in your delete conditions.
For example, the following command will fail:
DELETE FROM bootstrap WHERE duration > 1000;
This is because duration is not a time-based condition.
Correct Usage of Time in Delete Queries
To successfully delete entries based on time, you must include a time condition. For instance:
DELETE FROM bootstrap WHERE time > 1404140994043 AND duration > 300000;
This command will delete entries that meet both the time and duration criteria.
Additional Examples
Here are some additional delete commands that illustrate the correct usage:
DELETE FROM bootstrap WHERE time > 1404141416824 AND duration > 3000;
DELETE FROM bootstrap WHERE time > 1s AND duration > 1000;
Conclusion
If you encounter issues with delete commands in InfluxDB, ensure that your queries adhere to the requirement of referencing time. For further details, you can refer to the official InfluxDB documentation.