Skip to content
Snippets Groups Projects
Commit 745cbbf1 authored by Christoffer Stoll's avatar Christoffer Stoll
Browse files

Add totime trigger on timeserie

parent dd5365cc
No related branches found
No related tags found
No related merge requests found
......@@ -12,4 +12,5 @@ http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<include file="update_v9.sql" relativeToChangelogFile="true"/>
<include file="update_v10.sql" relativeToChangelogFile="true"/>
<include file="update_v11.sql" relativeToChangelogFile="true"/>
<include file="update_v12.sql" relativeToChangelogFile="true"/>
</databaseChangeLog>
-- SET TIMESTEP TO 60
update eea_times
set timestep = 60
where id = 'http://dd.eionet.europa.eu/vocabulary/uom/time/minute';
-- CREATE A FUNCTION TO UPDATE TOTIME FOR TIMESERIE
CREATE FUNCTION raven_timeserie_update_time()
RETURNS trigger
LANGUAGE 'plpgsql'
AS $$
DECLARE
fromtime timestamp without time zone;
totime timestamp without time zone;
BEGIN
SELECT oc.from_time, oc.to_time
INTO fromtime, totime
FROM observing_capabilities oc
WHERE sampling_point_id = NEW.sampling_point_id;
-- UPDATE FROMTIME IN THE OBSERVING CAPABILITIES TABLE
IF fromtime IS NULL OR NEW.from_time < fromtime THEN
UPDATE observing_capabilities SET from_time = NEW.from_time WHERE sampling_point_id = NEW.sampling_point_id;
END IF;
-- UPDATE TOTIME IN THE OBSERVING CAPABILITIES TABLE
IF totime IS NULL OR NEW.to_time > totime THEN
UPDATE observing_capabilities SET to_time = NEW.to_time WHERE sampling_point_id = NEW.sampling_point_id;
END IF;
RETURN NEW;
END;
$$;
-- CREATE A TRIGGER TO RUN FUNCTION AFTER OBS INSERT
CREATE TRIGGER raven_timeserie_update_time_trigger
AFTER INSERT
ON public.observations
FOR EACH ROW
EXECUTE PROCEDURE public.raven_timeserie_update_time();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment