Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the number of entries in a measurement

Tags:

influxdb

I am a newbie to influxdb. I just started to read the influx documentation.

I cant seem to get the equivalent of 'select count(*) from table' to work in influx db.

I have a measurement called cart:

time                status  cartid          
1456116106077429261 0       A
1456116106090573178 0       B
1456116106095765618 0       C
1456116106101532429 0       D

but when I try to do

select count(cartid) from cart

I get the error

ERR: statement must have at least one field in select clause
like image 448
zambro Avatar asked Feb 22 '16 05:02

zambro


People also ask

What is InfluxDB cardinality?

series cardinalityThe number of unique database, measurement, tag set, and field key combinations in an InfluxDB instance. For example, assume that an InfluxDB instance has a single database and one measurement. The single measurement has two tag keys: email and status .

How do you query in InfluxDB?

To perform an InfluxQL query, send a GET request to the /query endpoint, set the URL parameter db as the target database, and set the URL parameter q as your query. You can also use a POST request by sending the same parameters either as URL parameters or as part of the body with application/x-www-form-urlencoded .


1 Answers

This works as long as no field or tag exists with the name count:

SELECT SUM(count) FROM (SELECT *,count::INTEGER FROM MyMeasurement GROUP BY count FILL(1))

If it does use some other name for the count field. This works by first selecting all entries including an unpopulated field (count) then groups by the unpopulated field which does nothing but allows us to use the fill operator to assign 1 to each entry for count. Then we select the sum of the count fields in a super query. The result should look like this:

name: MyMeasurement
----------------
time    sum
0       47799

It's a bit hacky but it's the only way to guarantee a count of all entries when no field exists that is always present in all entries.

like image 189
wizzfizz94 Avatar answered Oct 31 '22 14:10

wizzfizz94