Is it possible to pass the timestamp retuned in influxDb query to another query.
Select max("value")
from "temp" where ("floor" = "1);
Output
time max
---- ---
2020-01-17T00:00:00Z 573.44
Is it possible to pass the time from the result to another query?
You cannot do this with InfluxQL,it is not possible to nest the queries in a way that could pass the time range of the inner query to the outer query. it's another matter if you were using Flux (new Query Language but still in BETA).
In Flux this is possible, because you can access time as a column, which you can then use to query your other measurements as required. You can also use JOIN to do more advanced operations like cross measurement calculations etc.
Related
I query all measurements from Influx database like so:
http://localhost:8086/query?pretty=true&db=boatdata&q=SELECT value FROM /.*/ LIMIT 1
Works fine. However, instead of LIMIT 1 I need to get values for all the measurements where value from one measurement=x, so I’d expect something like
SELECT value FROM /.*/ WHERE measurement1.value=x but it doesn’t work. I hope it makes sense. Any idea how to make it work? Thanks.
...to explain it better: in the first query (http://localhost…) I listed in this post I get a 1 record for all the measurements. But I want to get 1 record for all the measurements where value from measurement1 (one of the measurements) equals X.
This is impossible using InfluxQL. All measurements you ask are different series of data - so they are not grouped together in one table.
Idea of InfluxDB is that measurements are separate "tables" which are indexed by time and tag keys. I suggest you change your database architecture by writing values into different value fields.
You should have your data in one measurement to make query like you want.
You can move all your data from other measurements to one measurement for example by:
select "value" as "value1" from "measurement1" into "measurement" group by *
For each "measurement1" moved into "measurement" which will collect many value fields.
Then you will be able to make a query:
select * from "measurement" where "value1"=5
The query above should give you all value fields moved into "measurement" with the same timestamp where field "value1"=5.
Tip: If you have value1,value2,value3 in your measurement then you can use regex like:
select /value/ from "measurement" where "value1"=5
To avoid receiving tag key values or field values which you do not want.
I am trying to query data every nth element in InfluxDB. I am executing the command below to do so, but I am getting no results. I am using sample data that I created for the sake of the example.
The command I am running in Influx's CLI:
SELECT value FROM generators GROUP BY time(5s)
The result:
GROUP BY requires at least one aggregate function
I am new to InfluxDB, and I am not sure what I am doing wrong. I have read up on making a continuous query, but when I do make one, I am unable to query data as it returns no results. Thank you all to those in advance who reply.
You can use functions like FIRST() or LAST() depending on your requirement.
SELECT FIRST(value) FROM generators GROUP BY time(5s)
https://docs.influxdata.com/influxdb/v1.7/query_language/functions/
In InfluxDB v1.3, I have a measurement with one field and a tag that can take two values.
I would like to compute (x where mytag=y) - (x where mytag=z), using the last value of each series when needed (something like an http://code.kx.com/wiki/Reference/aj). I would like to do this in one query, if possible.
If the above is not possible, is there a different schema (e.g. using separate measurements) where what I would like to do is feasible? If so, can you please elaborate on the structure and the query?
SELECT difference(mean(x))
FROM <measurement>
WHERE time > now() - 1h and (mytag='y' OR mytag='x')
GROUP BY time(60s), mytag
Functions like difference require an aggregate query (group by time()) as well as an aggregation function for the values within the grouped window (mean above).
Difference then shows the differences between sequential aggregated values for the time period specified, additionally grouped by the two tag values specified.
These can be adjusted depending on your data.
I am trying to generate a continuous query in influxDB. The query is to fetch the hits per second by doing (1/response time) of the value which i am already getting for another series (say series1).
Here is the query:
select (1000/value) as value from series1 group by time(1s) into api.HPS;
My problem is that the query "select (1000/value) as value from series1 group by time(1s)" works fine and provide me results but as soon as I store the result into continuous query, it starts to give me parse error.
Please help.
Hard to give any concrete advice without the actual parse error returned and perhaps the relevant log lines. Try providing those to the mailing list at influxdb#googlegroups.com or email them to support#influxdb.com.
There's an email on the Google Group that might be relevant, too. https://groups.google.com/d/msgid/influxdb/c99217b3-fdab-4684-b656-a5f5509ed070%40googlegroups.com
Have you tried using whitespace between the values and the operator? E.g. select (1000 / value) AS value....
I have two write points for InfluxDB, one is the start and the other is the end. I just need to determine the duration between those two events, and make queries around it. InfluxDB has difference() aggregate method, but it doesn't work on the time meta field.
Is supplying a custom timestamp value the only way to accomplish this?
As per "Can I perform mathematical operations against timestamps?"
No:
"Currently, it is not possible to execute mathematical operators against timestamp values in InfluxDB. Most time calculations must be carried out by the client receiving the query results."
and yes, maybe:
The function ELAPSED() returns the difference between subsequent timestamps in a single field.
So it depends on the shape of your data.
If you write only the mentioned two entries then you can follow the below steps -
Limit the result to two (Eg: select * from timeseries limit 2)
Extract the time from the result set
Take the difference between the time