summaryrefslogtreecommitdiff
path: root/sql/populate_cache.sql
diff options
context:
space:
mode:
authorRandom Hacker <random_hacker@xapek.org>2011-12-05 22:47:24 +0100
committerRandom Hacker <random_hacker@xapek.org>2011-12-05 22:47:24 +0100
commit4f6f18fc3ad0f0a62f0db20e3e6e8d5a2bb190bf (patch)
tree6bfd35d2d61ee77dba8169afe24ca5d935d60803 /sql/populate_cache.sql
parentf7728b15fdea96376feea5daa187a7afb9ce6802 (diff)
downloadebus-alt-4f6f18fc3ad0f0a62f0db20e3e6e8d5a2bb190bf.tar.gz
ebus-alt-4f6f18fc3ad0f0a62f0db20e3e6e8d5a2bb190bf.zip
use current_timestamp; add notify
Diffstat (limited to 'sql/populate_cache.sql')
-rw-r--r--sql/populate_cache.sql12
1 files changed, 6 insertions, 6 deletions
diff --git a/sql/populate_cache.sql b/sql/populate_cache.sql
index f302607..2733cbb 100644
--- a/sql/populate_cache.sql
+++ b/sql/populate_cache.sql
@@ -1,9 +1,9 @@
drop table value_cache cascade;
CREATE TABLE value_cache (
-value_real integer,
-timestamp timestamp,
-sensor_id integer
+ value_real integer,
+ timestamp timestamp,
+ sensor_id integer
);
create or replace view vi_value_cache as
@@ -13,14 +13,14 @@ UNION
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')
+ CURRENT_TIMESTAMP - interval '2 days')
GROUP BY date_trunc('hour', timestamp), sensor_id;
;
CREATE OR REPLACE FUNCTION value_cache_aktualisieren() RETURNS timestamp AS $value_cache_aktualisieren$
DECLARE
- last_update timestamp = now();
+ last_update timestamp = CURRENT_TIMESTAMP;
BEGIN
select max(date_trunc('hour'::text, "timestamp"))
into last_update
@@ -28,7 +28,7 @@ BEGIN
RAISE NOTICE 'last update=%', last_update;
if last_update is NULL then
- last_update = now() - interval '20 days';
+ last_update = CURRENT_TIMESTAMP - interval '20 days';
RAISE NOTICE 'last update set to %', last_update;
end if;