diff options
author | yvesf <yvesf-git@xapek.org> | 2011-07-17 15:22:43 +0200 |
---|---|---|
committer | yvesf <yvesf-git@xapek.org> | 2011-07-17 15:22:43 +0200 |
commit | ba14c390b1f377bed6b46a83073bc35e0438b88e (patch) | |
tree | 2c8f5f3428d3259a1a88e6bb453724cd688bc9d9 /populate_cache.sql | |
parent | 214aeb0dd8bf2f979569a5070be09d2aa4653b81 (diff) | |
download | ebus-alt-ba14c390b1f377bed6b46a83073bc35e0438b88e.tar.gz ebus-alt-ba14c390b1f377bed6b46a83073bc35e0438b88e.zip |
cache auf int->real cast
Diffstat (limited to 'populate_cache.sql')
-rw-r--r-- | populate_cache.sql | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/populate_cache.sql b/populate_cache.sql index 0af4b36..0c30a18 100644 --- a/populate_cache.sql +++ b/populate_cache.sql @@ -1,18 +1,19 @@ drop table value_cache cascade; CREATE TABLE value_cache ( -value_int integer, +value_real integer, timestamp timestamp, sensor_id integer ); create or replace view vi_value_cache as - SELECT timestamp, sensor_id, value_int, 'CACHE' + SELECT timestamp, sensor_id, value_real, 'CACHE' FROM value_cache UNION - SELECT date_trunc('hour', timestamp), sensor_id, avg(value_int), 'LIVE' + SELECT date_trunc('hour', timestamp), sensor_id, COALESCE(avg(value_int),avg(value_real)), 'LIVE' FROM value - WHERE timestamp > coalesce( (select max(timestamp) from value_cache), now() - interval '2 days') + WHERE date_trunc('hour', timestamp) > coalesce((select max(timestamp) from value_cache), + now() - interval '2 days') GROUP BY date_trunc('hour', timestamp), sensor_id; ; @@ -34,9 +35,9 @@ BEGIN delete from value_cache where timestamp >= last_update; insert into value_cache - select avg(value_int), date_trunc('hour', timestamp), sensor_id + select COALESCE(avg(value_real),avg(value_int)), date_trunc('hour', timestamp), sensor_id from value - where date_trunc('hour', timestamp) >= last_update + where date_trunc('hour', timestamp) > last_update group by date_trunc('hour', timestamp), sensor_id; RETURN last_update; |