I’m trying to build a query to influx 1.8 that returns the difference between the latest values and the value 1 hour ago (or the latest and the last value in the last 1 hour period). I came up with a couple of queries, but it’s returning this query error:
A 400 Bad Request error occurred: {“error”:“error parsing query: missing parameter: timeFilter”}
My query that generated this error looks like this.
SELECT difference(last("value")) *1.723 FROM "autogen"."temp_values" WHERE time > now() - 1h AND ("topic" = '/temperature/q2') AND $timeFilter GROUP BY time(1h) fill(none)
Also tried variations like this
SELECT difference(last("value")) *1.723 FROM "autogen"."temp_values" WHERE ("topic" = '/temperature/q2') AND $timeFilter GROUP BY time(1h) fill(none)
I want to multiply the difference beween the most recent and the least recent values in that 1 hour period by a scale factor 1.723, hence the number in the query.
That $timeFilter
tells me you are using Grafana, that placeholder will be replaced with the time filter set by the user…
but given the error, it seems like it’s not getting replaced at all
The second query seems fine to me (if ran via grafana)
SELECT difference(last("value")) *1.723 FROM "autogen"."temp_values" WHERE ("topic" = '/temperature/q2') AND $timeFilter GROUP BY time(1h) fill(none)
I need to know how you are quering InfluxDB (Grafana, CLI, API), to me the issue is in the tool/client before the query is even sent to InfluxDB.
Yes, you’re right. The client I’m actually using is a javascript client. I found a working example in Grafana (hence I was using a query with the the timeFilter keyword) and was scratching my head on why the javascript query wasn’t working. I didn’t know Grafana queries were different than pure Influx queries.
So, putting aside Grafana, I’m looking for a pure Influx query that would return the difference between the oldest value and the most recent value in a time range (say 1 hour).
this will group the results in 1h buckets, creating multple if needed
SELECT
difference(last("value")) *1.723
FROM "autogen"."temp_values"
WHERE
"topic" = '/temperature/q2'
AND time > now() - 1 h
GROUP BY
time(1h) fill(none)
But I think you are looking for something more like this, without group by
SELECT
(last("value") - first("value")) *1.723 as "myValue"
FROM "autogen"."temp_values"
WHERE
"topic" = '/temperature/q2'
AND time > now() - 1 h