I have a Influx db (V1.8- FLUX disabled by hoster). I want to "add" a column to the measurement which uses the estimated function.
Initial Measurement look like:
time Current state_string
---- ------- ------------
1577836800000000000 0 off
1577836860000000000 0.125 off
1577836920000000000 0.25 standby
1577836980000000000 0.375 standby
1577837040000000000 0.5 standby
1577837100000000000 0.625 on
1577837160000000000 0.75 on
1577837220000000000 0.875 in use
1577837280000000000 1 in use
Then i would like to add a column which calculates the estimated time:
select elapsed("state", 1s) as "time_in_state" from "device_measurements" where hardware_sensor_id = '31c32c1b-119e-4167-0'
which results in:
time time_in_state
---- -------------
1577836860000000000 60
1577836920000000000 60
1577836980000000000 60
1577837040000000000 60
1577837100000000000 60
1577837160000000000 60
1577837220000000000 60
1577837280000000000 60
So far so good. Then i wold like to join those two tables and store them in a new one, while preserving the tags. (my real measurements have more tags which are omitted for simplicity here)
I came up with:
select time_in_state into "device_measurements" from
(select elapsed("state", 1s) as "time_in_state" from "device_measurements" where hardware_sensor_id = '31c32c1b-119e-4167-0' group by * )
group by *
I have read that group by * is needed to preserve tags. But i causes one issue:
time Current state_string time_in_state
---- ------- ------------ -------------
1577836800000000000 0 off
1577836860000000000 0.125 off 60
1577836920000000000 0.25 standby
1577836980000000000 0.375 standby 60
1577837040000000000 0.5 standby 60
1577837100000000000 0.625 on
1577837160000000000 0.75 on 60
1577837220000000000 0.875 in use
1577837280000000000 1 in use
As you can see the time_in_state column is not calculated for every row. This is caused by the group by clause...
How can i fromulate the query so that I achieve a table with the tags and the time_in_state for every column. I have read the join() documentation but somehow can't translate the things i read there to code.