occasionally I have the need to correct single or multiple datapoints in my Influx2 DB, add some, or remove others. Since the builtin UI doesn’t have this capability, I want to script this. But before I start and go into the wrong direction: is it possible to UPDATE values in Influx2 databases at all? Can I retrieve annotated CSV values using Flux, and then take this annotated CSV (with possibly modified _value columns, or added and deleted rows) and upload it again and Influx will update existing data?
If this is not directly possible, how do I accomplish this?
In order to update a point you need to insert that very same point with different field values, this will cause an update.
In order for it to succeed it must have the same series and timestamp. You can only update field values, any other “update” (i.e. on tag values) requires a delete and insert
You can add rows as you like, just use the proper series in order to find them later.
OK, thank you so the first potential show stopper is solved.
When editing, I can make the non-field values readonly.
Followup question: Is there a way to retrieve data, in a format that could be re-inserted without change?
As far as I have understood the docs, a query can only return CSV data, but this doesn’t include annotation headers. But an insert requires either line protocol or fully annotated CSV. So it’s not possible to do query a set of records in a format that would be directly insertable into another database / influx instance / whatever. If this is true, one could say “Influx cannot speak to itself” …
@Jens, you can write annotated CSV to InfluxDB, but currently only with the influx write command or through the InfluxDB UI.
However, if you’re doing the value updates in Flux, you can just use to() to write the modified values back to InfluxDB. to() structures the data as line protocol and writes it back to InfluxDB.
This will overwrite the existing values with the updated values.
To add lines of data, you don’t really need to query data out. You can just write the new points with appropriate timestamps and tags and InfluxDB will figure out the rest.
To delete data, you need to use the /api/v2/delete API or influx delete command. More information is available in the documentation – Delete data from InfluxDB
My intention actually is to write an interactive “table editor” somewhat like phpMyAdmin or SQL Studio for Influx, where users can edit and resubmit field values, and (possibly later) also add new values or delete incorrect values. To be able to do that, I need to retrieve data from a measurement and submit the values for update.
My impression is that I can not keep the tabular format, but I’d have to convert the data to line protocol to be able to resubmit them to Influx for an update, and be careful that all tags are kept so that no accidental new values are created.
I think you are right, but that’s also up to how you interact with the DB as some client libraries “hide” the line protocol.
I have no idea about what’s your use case, but InfluxDB does not encourage updates and deletes on data.
In a “standard” use case (like monitoring) I’d consider it madness to access the data at single point granularity as there are millions of data points (in my case, which is not that big I write ~315000 per minute)