Delete old data from measurements

I want to delete data from measurements using influxql that will run every 30days. But am unable to do. I tried using the sample delete queries, but they are showing errors under the influx2.0 schedule-task

@Aritra666B This seems like you could just use a 30 day retention period on a bucket. Any data in the bucket with timestamps older than 30 days would automatically get dropped. Is there a specific reason you don’t want to do that?

hi @scott , so we have multiple tables in a bucket & we need to delete data of one table after 30 days & rest will be different. That’s why I want to do this.

Hi @Aritra666B,
In future, I would look to shift the measurements from this bucket into new buckets with different retention policies. This can be done with the to() command. To answer your current question, there is currently no flux function for deleting data from your bucket. What you could make use of the http(). As part of a task you can send the delete command like so:

import "http"
import "json"


http.post(
  url: "https://us-east-1-1.aws.cloud2.influxdata.com/api/v2/delete?bucket=testdata&precision=s&org=<org>",
  headers: {Accept: "application/json", Authorization: "Token <TOKEN>", Content-Type: "application/json"},
  data: json.encode(v: '{
"predicate": "tag1=\"value1\" and (tag2=\"value2\" and tag3!=\"value3\")",
"start": "2019-08-24T14:15:22Z",
"stop": "2019-08-24T14:15:22Z"
}')
)

As you can see this gets a little messy so I highly recommend the to() method with separate retention policies.