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
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 .
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With