Snow bunting
Snow bunting

Reputation: 1221

How to delete a point in influxDB

Sorry this is almost certainly a duplicate but I'm just not able to put the informations together.

How do I delete a point from influxDB? First I use Python and the DataFrameClient:

client = DataFrameClient('localhost', '8086', 'root', 'root', 'meteo')

Then I write multiple points like:

meta = pd.DataFrame({'path': ['A'],
                     'table': ['B'],
                     'md5': ['C']},
                     index=[pd.datetime.now()])
client.write_points(dataframe=meta,
                    measurement='__SRC__',
                    protocol='line',
                    database='meteo')

Now I would like to delete all points, where path is 'A'. My attempt using client.query:

DELETE FROM "meteo"."autogen"."__SRC__" WHERE path='A'

> received status code 400 from server: err: error parsing query:
>     retention policy not supported at line 1, char 1

Now this message has probably a meaning, but could you help me on what I'm doing wrong and where to read about it? Thank you a lot!

Update

Following the answer of @JanGaraj, I have some more results. The following query (I have a var. table instead of path but wouldn't see how this makes a difference.)

client = influxdb.DataFrameClient('localhost', '8086', 'root', 'root', 'meteo')
client.query('DELETE  FROM "__SRC__" WHERE table=\'A\'')

returns

ResultSet({})

but does not delete anything (with SELECT * FROM "__SRC__" WHERE table=\'A\' i get 4 datapoints).

The same query (DELETE FROM "__SRC__" WHERE table='A') put into Chronograf gives "database not found:", which makes sense but I wouldn't know how to fix it.

Upvotes: 2

Views: 11510

Answers (4)

r02
r02

Reputation: 301

Regardless of the actual query string, you're missing one big component here - when using the InfluxDB client, you need to specify the method to be POST, as it defaults to GET for querying the database and getting the points back - which is why your query returns a ResultSet and does not delete the points. So, you need to use:

client.query(query_str, method="POST")

You can take a look at the InfluxDB client implementation for some examples.

Upvotes: 0

user3873769
user3873769

Reputation: 1

You can specify time range with vary close range. For example 1 microsecond

delete from "rs_5f5b34f89aded07f6dba81e0" where time >=1599858000000000000 and time < 1599858000000000001

Upvotes: 0

Yuri G
Yuri G

Reputation: 1213

First of all, by DELETE specification, you, effectively, can't delete a single point - you delete all points in a series.

In practice, in this case, you can consider that tags make a series (oversimplification, but that works here).

And tags are what DELETE takes to define a series to be affected - never values!

In other words, you can specify ONLY tags in your WHERE.

Now, what I get from this Py library doc(-), that DataFrame is considered as set of values, NOT tags.

And that is exactly why it does not work: you should put your path (and most likely, table too, consider the cardinality here) into the tags (separate parameter in your call), NOT values.

Then it's gonna work, but the question is - why would you need to delete the points at all? Could you answer this question?

-) The thing is truly disgusting, I must admit, don't know how you guys manage to stand it & not run away immediately to some more humanely designed & DOCUMENTED libs & languages

Upvotes: 1

Jan Garaj
Jan Garaj

Reputation: 28626

Try query:

DELETE FROM "__SRC__" WHERE path='A'

DB and retention policy is not supported in the FROM part in this case - see InfluxDB DELETE doc.

Upvotes: 0

Related Questions