diff options
Diffstat (limited to 'populate_cache.sql')
-rw-r--r-- | populate_cache.sql | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/populate_cache.sql b/populate_cache.sql index 0c30a18..f13fa85 100644 --- a/populate_cache.sql +++ b/populate_cache.sql @@ -10,7 +10,7 @@ create or replace view vi_value_cache as SELECT timestamp, sensor_id, value_real, 'CACHE' FROM value_cache UNION - SELECT date_trunc('hour', timestamp), sensor_id, COALESCE(avg(value_int),avg(value_real)), 'LIVE' + SELECT date_trunc('hour', timestamp), sensor_id, COALESCE(avg(value_int),avg(value_float)), 'LIVE' FROM value WHERE date_trunc('hour', timestamp) > coalesce((select max(timestamp) from value_cache), now() - interval '2 days') @@ -35,7 +35,7 @@ BEGIN delete from value_cache where timestamp >= last_update; insert into value_cache - select COALESCE(avg(value_real),avg(value_int)), date_trunc('hour', timestamp), sensor_id + select COALESCE(avg(value_float),avg(value_int)), date_trunc('hour', timestamp), sensor_id from value where date_trunc('hour', timestamp) > last_update group by date_trunc('hour', timestamp), sensor_id; |