Read/Delete data with a specific time in golang

Hello,

I need some help on how to write query in flux in golang which can select/delete data on a particular time and not time range
I understand the range function as explained in range() function | Flux Documentation
but unfortunately I am not able to use a specific time in the query. I tried using start and stop with same value(like below) but it does not work.

For example , I want to see data with only timestamp 2023-12-01T21:30:50Z

  1. Below query gives error " error in building plan while starting program: cannot query an empty range"
    |> range(start: 2023-12-01T21:30:50Z, stop: 2023-12-01T21:30:50Z)

  2. And The below query yeilds nothing
    |> range(start: 2023-12-01T21:30:50Z, stop: 2023-12-01T21:30:51Z)
    |> filter(fn: (r) => r[“_time”]== 2023-12-01T21:30:50Z)

However, if filter is removed I can see some data.

Thanks in advance for any help.

Can you paste those rows into a preformatted code block </> ?

Can you also paste the full query in a code block too

Hello @FixTestRepeat ,

I try to re paste the queries. Please let me know if the formatting is ok with you.

  1. Query:
from(bucket: "Edgex") 
|> range(start:  2023-12-01T21:30:50Z, stop:  2023-12-01T21:30:50Z)

Response:

 error in building plan while starting program: cannot query an empty range
  1. Query(increased 1 second in range)
from(bucket: "Edgex")
|> range(start:  2023-12-01T21:30:50Z, stop:  2023-12-01T21:30:51Z)

Response:

_start_stop_time_field_measurementcounterdevicenamesourcename_value (string)2023-12-01 22:30:50 GMT+12023-12-01 22:30:51 GMT+12023-12-01 22:30:50 GMT+1eventidContainer-Statistics1Container-StatisticsCPUe3993927-d02b-437b-a75d-48fdd4eaa657
12
  1. Query:
from(bucket: "Edgex")
|> range(start:  2023-12-01T21:30:50Z, stop:  2023-12-01T21:30:51Z)
|> filter(fn: (r) => r["_time"]== 2023-12-01T21:30:50Z)

Result:

No Results

Thanks , formatting is fine - this above output was what I was wondering to see. This isn’t a style I recognize - maybe unique to the Golang plugin . Given the behavior you’re getting it makes me think there is extra time precision in these records that isn’t visible. ( The start time would be treated internally as 2023-12-01T21:30:50.000000000Z)

Without knowing your use case, if you’re expecting a single record to be returned when you use the 1 second range query,instead of using the final pipe into filter, you could pipe into first()

Ie.

from(bucket: "Edgex")
|> range(start:  2023-12-01T21:30:50Z, stop:  2023-12-01T21:30:51Z)
|> first()

Hello @FixTestRepeat
For the moment, I am executing the queries in Data Explorer of Influx web interface and not in golang.

And from the second query there are different tables grouped by tags displayed as a result withing the time range. I just pasted one table data.

The question is how to select data with a specific time and not a time range.

Ah, I missed that you were pulling from a bucket with no filter on a measurement .

The response you did get when extending the range query to include and end time still looks strange. Is the output expected for you ?

What started you down the path for using range() ? Is anything stopping you from just using filter() on the specific time point?

If you need to use range() , As an experiment, can you add a filter on two or three measurements , that still produce the problem?

What’s the smallest number of rows/tables that still give the same behavior . Can you paste those in a code block too.

Hello @FixTestRepeat ,

The second query with a stop value one second more(2023-12-01T21:30:51Z) than the start (2023-12-01T21:30:50Z)was for testing purpose. I wanted to see if the records with time 2023-12-01T21:30:50Z is correctly fetched and yes it was fetching . Ofcourse the query also included the records with time 2023-12-01T21:30:51Z and surely I dont want that. I only want to fetch the records for the specific time 2023-12-01T21:30:50Z.

Understood, but why use range . Have you tried just using filter on a specific timestamp?

Hello @FixTestRepeat ,

Well, I was not able to execute a query without using range. Can you please provide an example.
However, I did try using range first and then filter on the specfic time and the there was no result
3. Query:

from(bucket: "Edgex")
|> range(start:  2023-12-01T21:30:50Z, stop:  2023-12-01T21:30:51Z)
|> filter(fn: (r) => r["_time"]== 2023-12-01T21:30:50Z)

Output:

No Results

I have

I found a workwround for the queries and the deleteAPI works fine with particular time