TL;DR InfluxDB Tech Tips - Understanding Dependent Tags In Series Cardinality
By Regan Kuchan / Dec 15, 2016 / Tech Tips
In this weekly post we recap the most interesting InfluxDB series cardinality and TICK-stack related issues, workarounds, how-tos and Q&A from GitHub, IRC and the InfluxDB Google Group that you might have missed in the last week or so.
Writing timestamps to InfluxDB
Q: I’m new to InfluxDB and am learning to work with line protocol. I have historical data that I’d like to write to my database - is that possible with line protocol? Could you give me an overview of the supported timestamp formats?
A: Sure! InfluxDB’s timestamps are always in Unix time; that’s the amount of time that has elapsed since midnight UTC on January 1, 1970.
Timestamps in line protocol, the text-based format for writing points to InfluxDB, are optional. If you do not supply a timestamp, InfluxDB writes the point to the database using your server’s local nanosecond time in UTC. If you do specify a timestamp, InfluxDB writes the point using that timestamp instead. So to answer your initial question: yes, you can write historical data to your database, you just need to specify the relevant timestamp in your line protocol.
There are a couple other things to know about writing timestamps to InfluxDB:
- The maximum allowable timestamp is
- The minimum allowable timestamp is
1677-09-21 00:12:43.145224194. Notice that InfluxDB supports negative Unix timestamps, that is, timestamps that occur before midnight UTC on January 1, 1970.
- The HTTP API supports writing non-nanosecond timestamps. Just use the
precisionquery string parameter to specify that timestamps are in microseconds (
u), milliseconds (
ms), hours (
h), minutes (
m), or seconds (
s). We recommend using the coarsest precision possible when writing data to InfluxDB. It can result in significant improvements in compression.
Understanding dependent tags in series cardinality
For example, I have a single measurement with the tag keys
firstname has five different tag values,
lastname has five different values, and
Working with your example, if we have the tags
lastname are dependent variables, and
Selecting disparate time ranges
Q: I’m trying to
SELECT data with a time range in the
WHERE clause but I keep getting no results. Is there something wrong with my query?
SELECT * FROM "holidata" WHERE (time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:06:00Z') OR (time >= '2015-09-18T21:36:00Z' AND time <= '2015-09-18T21:42:00Z')
A: Currently, InfluxQL doesn’t support selecting disparate time ranges in the
WHERE clause. Your query isn’t returning any results because there’s a time gap between your two time ranges. You can get around that by splitting your query into two separate queries:
# Query 1 for time range one SELECT * FROM "holidata" WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:06:00Z'
# Query 2 for time range two SELECT * FROM "holidata" WHERE time >= '2015-09-18T21:36:00Z' AND time <= '2015-09-18T21:42:00Z'
- Downloads for the TICK-stack are live on our "downloads" page
- Deploy on the Cloud: Get started with a FREE trial of InfluxDB Cloud featuring fully-managed clusters, Kapacitor and Grafana.
- Deploy on Your Servers: Want to run InfluxDB clusters on your servers? Try a FREE 14-day trial of InfluxDB Enterprise featuring an intuitive UI for deploying, monitoring and rebalancing clusters, plus managing backups and restores.
- Tell Your Story: Over 100 companies have shared their story on how InfluxDB is helping them succeed. Submit your testimonial and get a limited edition hoodie as a thank you.