TL;DR InfluxDB Tech Tips - InfluxQL Query Examples
By
Jimmy Guerrero /
Developer
Jul 07, 2016
Navigate to:
In this post we recap the week’s most interesting influxQL query examples, InfluxDB and TICK-stack related issues, workarounds, how-tos and Q&A from GitHub, IRC and the InfluxDB Google Group that you might have missed.
Understanding unexpected fill() behavior
Q: I’m using fill(0)
in my query but it doesn’t return any results. Is this the expected behavior?
A: If none of your data fall within your query’s time range, your query will return no results - even if your query includes fill()
. This is how fill()
currently works but there is an open issue to change that behavior.
For example:
Write one data point:
> INSERT invisible person=7 1467842220000000000
> SELECT * FROM "invisible"
name: invisible
---------------
time person
2016-07-06T21:57:00Z 7
Use fill(0)
and query a time range that includes the point:
> SELECT mean("person") FROM "invisible" WHERE time >= '2016-07-06T21:57:00Z' AND time <= '2016-07-06T21:59:00Z' GROUP BY time(1m) fill(0)
name: invisible
---------------
time mean
2016-07-06T21:57:00Z 7
2016-07-06T21:58:00Z 0
2016-07-06T21:59:00Z 0
Use fill(0)
and query a time range that doesn’t include the point:
> SELECT mean("person") FROM "invisible" WHERE time >= '2016-07-06T21:58:00Z' AND time <= '2016-07-06T21:59:00Z' GROUP BY time(1m) fill(0)
Querying for the latest point in a measurement
Q: I’m trying to find the last point in my measurement. I’ve included the query that I use to do that, but I’m wondering - is there a better way to do this?
> SELECT "dance_id" FROM "ballroom" ORDER BY time DESC LIMIT 1
name: ballroom
--------------
time dance_id
2016-07-06T20:26:10Z 103
A: Yes! There’s an InfluxQL function (LAST()
) that returns the last point in a measurement:
> SELECT last("dance_id") FROM "ballroom"
name: ballroom
--------------
time last
2016-07-06T20:26:10Z 103
InfluxDB Tech Tips Video
Check out the video below from the June 2016 InfluxDB Meetup for tips on series cardinality, INTO
queries, and more.
For more InfluxDB tips, see our Frequently Asked Questions page and feel free to post your questions in the InfluxDB users group.
What's next?
- Looking for InfluxDB clustering on your infrastructure? Get started with InfluxDB Enterprise Beta, now available for evaluation.
- Download and get started with InfluxDB 1.0 Beta 2
- Schedule a FREE 20 minute consultation with a Solutions Architect to review your InfluxDB project
- Attend one of our FREE virtual training seminars.