ices-eg / wg_WGEEL

Joint EIFAAC/ICES/GFCM Working Group on Eels
http://ices.dk/community/groups/Pages/WGEEL.aspx
5 stars 12 forks source link

trigger coordinates update #165

Closed elfunesto closed 3 years ago

elfunesto commented 3 years ago

The previous triggers on t_series_ser raises problem to update coordinates, however, it would be great to have trigger that ensure that ser_x,ser_y and geom are always synchronised. With the following block, geom is computed from ser_x and ser_y at insert. Then, if we update either ser_x or ser_y, geom is automatically updated. Conversely, if we update geom, ser_x and ser_y are updated.

`create trigger update_geom after insert or update of ser_x,ser_y on datawg.t_series_ser for each row execute procedure datawg.update_geom();

CREATE OR REPLACE FUNCTION datawg.update_coordinates() RETURNS trigger LANGUAGE plpgsql AS $function$ BEGIN NEW.ser_x = st_x(geom); NEW.ser_y = st_y(geom); RETURN NEW; END; $function$ ;

create trigger update_coordinates after update of geom on datawg.t_series_ser for each row execute procedure datawg.update_coordinates(); `

elfunesto commented 3 years ago

Done, script added in database_edition_2020.sql commit dff054bd47211c58398fa4574e06776388f9fe57