TL;DR InfluxDB Tech Tips - Using Single Quotes vs Double Quotes Within InfluxQL

Navigate to:

In this post we recap the week’s most interesting InfluxDB and TICK-stack related issues, workarounds using single quotes vs double quotes within InfluxQL, how-tos and Q&A from GitHub, IRC and the InfluxDB Google Group that you might have missed.

Specifying time in queries

Q: I see that when I write data to InfluxDB, Line Protocol only accepts time in epoch format. Do queries also only accept time in epoch format?

A: InfluxQL accepts several different time formats in addition to epoch timestamps. Queries work with both relative time formats and absolute time formats.

For relative time, use now() with a valid time duration unit to specify a time based on the current Unix time of the server. For example, select everything from the measurement einstein with timestamps that occur in the past 10 minutes:

SELECT * FROM "einstein" WHERE time > now() - 10m

For absolute time, use date-time strings in RFC3339-like format, date-time strings in RFC3339 format, or epoch time. For example, the following three queries select everything from the measurement absolutismus where the time is Wednesday, July 20, 2016 at 16:00:00:

SELECT * FROM "absolutismus" WHERE time = '2016-07-20 16:00:00' 
SELECT * FROM "absolutismus" WHERE time = '2016-07-20T16:00:00Z'
SELECT * FROM "absolutismus" WHERE time = 1469030400000000000

For more on specifying time in queries, check out Data Exploration.

Specifying multiple functions in a query

Q: I want to calculate the minimum and maximum for the same field at the same time. Currently, I’m doing this with two queries separated by a semicolon but it seems like a lot of text. Is there a simpler way to do this?

The two queries:

curl -GET 'http://localhost:8086/query?db=claymation&pretty=true' --data-urlencode 'q=SELECT min("movement") FROM "take_1";SELECT max("movement") FROM "take_1"'

A: Yes! You can include more than one function in a single query; just separate the functions with a comma:

SELECT min("movement"),max("movement") FROM "take_1"

Selecting data where a tag has no value

Q: I want to select field values from a measurement where a specific tag has no value. I’ve tried to do this with "" but I get no results back. Is there a way to do this in InfluxQL?

> SELECT * FROM "vases"
name: vases
time                   origin   priceless
2016-07-20T18:42:00Z   8
2016-07-20T18:42:00Z   1        yes

> SELECT * FROM "vases" WHERE priceless=""

A: Yes, specify empty tag values with single quotes:

> SELECT * FROM "vases" WHERE priceless=''
name: vases
time                   origin   priceless
2016-07-20T18:42:00Z   8

Check out single quoting and double quoting in queries for more information!

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?