mnzl
mnzl

Reputation: 340

downsampling: get constant value. E.g. sensor name from GROUP BY

I created a continuous query to downsample readings from temperature sensors in my influxdb to store hourly means for a longer time. There are readings of multiple sensors in one table. Upon executing the query, the sensors ip is missing.

Basic data looks like this:

> SELECT ip,tC  FROM ht LIMIT 5
name: ht
time                ip           tC
----                --           --
1671057540000000000 192.168.0.83 21
1671057570000000000 192.168.0.83 21
1671057750000000000 192.168.0.17 21.38

The continuous query (simplified without CREATE ... END):

SELECT last(ip), mean("tC") AS "mean_temp" INTO "downsampled"."ht_downsampled"  FROM "ht"  GROUP BY time(1h),ip

The issue is, the value of 'ip' is only a tag, not the value in the table and subsequently is missing in the table the query inserts into:

name: ht
tags: ip=192.168.0.17
time                ip mean_temp          mean_hum
----                -- ---------          --------
1671055200000000000    21.47              42.75
1671058800000000000    21.39428571428571  48.785714285714285
1671062400000000000    21.314999999999998 51.625

Why is last(ip) not producing any value? Can I get the value from the 'tags' into the table? Is there a different approach to group data with a constant value?

Upvotes: 0

Views: 141

Answers (1)

Munin
Munin

Reputation: 1649

Could you just try query the ip instead of the last(ip) since you are grouping by the ip in the statement already?

Sample code:

SELECT ip, mean("tC") AS "mean_temp" INTO "downsampled"."ht_downsampled"  FROM "ht"  GROUP BY time(1h), ip

Upvotes: 2

Related Questions