On insert in tbl1, the trigger I am working on, copies rows in tbl2 with some updates.
create or replace function myprocedure() returns trigger asbegin IF (TG_OP = 'INSERT')THEN insert into tbl2 select new.* from tbl1 ;update tbl2set (field1, field2) = ... ; return new ; END IF ;END;$$ LANGUAGE plpgsql ;DROP TRIGGER IF EXISTS mytrig ON public.tbl1 ; CREATE TRIGGER mytrig AFTER INSERT or UPDATE on public.tbl1FOR EACH ROW EXECUTE PROCEDURE myprocedure();problem is : the first insert in tbl1 gives 1 insert in tbl2. FIne.The second insert in tbl1 gives 2 (identical) lines in tbl2 (values of second insert) ,The third insert in tbl1 gives 3 (identical) lines in tbl2 (values of third insert) etc.
I am feeling a little lostAny help ?Thanks
أكثر...
create or replace function myprocedure() returns trigger asbegin IF (TG_OP = 'INSERT')THEN insert into tbl2 select new.* from tbl1 ;update tbl2set (field1, field2) = ... ; return new ; END IF ;END;$$ LANGUAGE plpgsql ;DROP TRIGGER IF EXISTS mytrig ON public.tbl1 ; CREATE TRIGGER mytrig AFTER INSERT or UPDATE on public.tbl1FOR EACH ROW EXECUTE PROCEDURE myprocedure();problem is : the first insert in tbl1 gives 1 insert in tbl2. FIne.The second insert in tbl1 gives 2 (identical) lines in tbl2 (values of second insert) ,The third insert in tbl1 gives 3 (identical) lines in tbl2 (values of third insert) etc.
I am feeling a little lostAny help ?Thanks
أكثر...