Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 0.71 KB | None | 0 0
  1. CREATE OR REPLACE FUNCTION insert_operations_trigger()
  2.   RETURNS TRIGGER AS
  3. $BODY$
  4.     DECLARE
  5.         SQL text;
  6.         m RECORD;
  7.         r macnoms.operations;
  8.     BEGIN  
  9.         IF EXISTS (SELECT 1 FROM macnoms.operations WHERE opnum=NEW.opnum)  THEN
  10.             SELECT INTO r * FROM macnoms.operations WHERE opnum=NEW.opnum;
  11.             NEW.lastmod := NULL;
  12.             r.lastmod:=NULL;
  13.             IF ROW(r.*) IS DISTINCT FROM ROW(NEW.*) OR NOT(r.the_geom ~ NEW.the_geom AND st_equals(r.the_geom,NEW.the_geom)) THEN
  14.                 DELETE FROM macnoms.operations WHERE opnum=NEW.opnum;
  15.             ELSE
  16.                 RETURN NULL;
  17.             END IF;
  18.         END IF;
  19.         NEW.lastmod=now();
  20.         RETURN NEW;
  21.     END;
  22. $BODY$
  23.   LANGUAGE plpgsql VOLATILE
  24.   COST 100;
  25. ALTER FUNCTION insert_operations_trigger() OWNER TO pgsql;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement