diff --git a/interface/import/map_trigger.sql b/interface/import/map_trigger.sql index 9cae932..fb51950 100644 --- a/interface/import/map_trigger.sql +++ b/interface/import/map_trigger.sql @@ -1,6 +1,35 @@ -CREATE OR REPLACE FUNCTION tps.trans_insert_map() RETURNS TRIGGER AS $f$ +CREATE OR REPLACE FUNCTION tps.trans_insert_map() RETURNS TRIGGER +AS +$f$ + DECLARE + _cnt INTEGER; + BEGIN IF (TG_OP = 'INSERT') THEN + + --------determine if there are any maps for the source involved---- + SELECT + COALESCE(COUNT(*),0) + INTO + _cnt + FROM + tps.map_rm m + INNER JOIN new_table t ON + t.srce = m.srce; + + ---------if there are no maps then set allj to rec and exit--------- + IF _cnt = 0 THEN + UPDATE + tps.trans t + SET + allj = n.rec + FROM + new_table n + WHERE + t.id = n.id; + RETURN NULL; + END IF; + WITH --------------------apply regex operations to transactions----------------------------------------------------------------------------------- @@ -226,4 +255,4 @@ $f$ LANGUAGE plpgsql; CREATE TRIGGER trans_insert AFTER INSERT ON tps.trans REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT EXECUTE PROCEDURE tps.trans_insert_map(); + FOR EACH STATEMENT EXECUTE PROCEDURE tps.trans_insert_map(); \ No newline at end of file