[Mapbender-users] PostgreSQL trigger function

Daniel Grum daniel.grum at unibw.de
Thu Dec 3 17:16:01 EST 2009


is there a way to build a simple INSERT trigger function like that:

CREATE OR REPLACE FUNCTION einheitenstandort()
 RETURNS trigger AS
$BODY$   BEGIN

   INSERT INTO einheitenstandort
   SELECT         nextval('serial') AS GID,
           startpoint(line.the_geom) AS the_geom,
           line.name_der_einheit AS name_der_einheit,
           line.art AS art,
           (SELECT a.geschwindigkeit WHERE line.art = a.art) AS 
geschwindigkeit,
           localtimestamp AS zeitpunkt
   FROM    public.einheiten_und_bewegungen line, public.art_der_einheit 
a, public.einheitenstandort es;
            END; $BODY$
 LANGUAGE 'plpgsql' VOLATILE
 COST 1000;
ALTER FUNCTION einheitenstandort() OWNER TO postgres;

Or are more infos need to be in the triggerfunction????

The trigger of the table einheiten_und_bewegungen is:

 CREATE TRIGGER my_trigger
 AFTER INSERT OR UPDATE OR DELETE
 ON einheiten_und_bewegungen
 FOR EACH ROW
 EXECUTE PROCEDURE einheitenstandort();

The idea is, that everytime when a new "einheitenbewegung" was digitized 
over the WFS-T an INSERT was made in the table einheitenstandort-->the 
actual position of the unit.

Thanks for all ideas!
--daniel


More information about the Mapbender_users mailing list