0

Extending this Using InfluxDB difference function a bit further, I have

select difference("e") from Energy where time >= now() - 24h

or

select difference("e") from Energy where time >=
'2020-04-14T00:00:01Z' and time <= '2020-04-15T20:00:01Z'

both working where the time search only covers 2 datapoints for the subtraction.

But how do I achieve this in a python script? The best I have is

response = client.query(select difference("e") from Energy where time
>= now() - 24h)

but it returns an Invalid syntax error. Any clues to implement difference() in python?

Rob B
  • 31
  • 5

2 Answers2

0

Your whole query has to a python string. Try something like:

response = client.query('select difference("e") from Energy where time >= now() - 24h')
rolf82
  • 1,531
  • 1
  • 5
  • 15
  • Thanks. Yes in bash this works: `influx -database EnergTotal -execute 'select difference("e") from Energy where time >= now() - 24h'` but getting the syntax right for python is a challenge as it requires the database name. I have tried a niumber of options around `response = client.query('database=EnergTotal select difference("e") from Energy where time >= now() - 24h')` without success. – Rob B Apr 16 '20 at 08:56
0

The query has to be first and then the database name:

response = client.query('select difference("e") from Energy where time >= now() - 24h', database='EnergTotal')

Hope this helps some others. And thanks @rolf82.

Rob B
  • 31
  • 5