From 1ff496e0720a28d39686cde1e235da7a35998932 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Fri, 25 May 2018 14:22:23 -0400 Subject: [PATCH] if no map, set allj to rec. allj still an issue tho --- interface/import/map_trigger.sql | 33 ++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) 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