1

i am experimenting with triggers in postgreSQL, but the trigger insert i would like to make is being done twice for some reason(THIS IS USING THE FOR EACH ROW), when i changed it to FOR EACH STATEMENT it was executing the insert 3 times. this is my sql script

CREATE OR REPLACE FUNCTION forest_aud_func() returns trigger as $tree_stamp$ 
BEGIN
    insert into Audit values('k',124,'l');
    return null;
END;
$tree_stamp$
LANGUAGE plpgsql;

create trigger forest_aud_ins after insert on forest
for each row execute procedure forest_aud_func()

insert into forest values('Blue',1600,'Austria','Health Ltd')

any idea why this is happening? Thanks

3
  • 1
    You should not return null from your trigger. That will stop processing the insert! Commented Jan 11, 2012 at 12:27
  • it still does the insert for me with return null, i don't think its the problem, or did you mean something else? Commented Jan 11, 2012 at 12:38
  • this is strange, because the manual clearly states that the insert (in your case the insert into forest) will be aborted if the trigger returns null. Commented Jan 11, 2012 at 13:09

1 Answer 1

2

i found out the problem, i was always creating new triggers but not deleting the previous ones, so each time i do an insert it was firing all the triggers i had done, sorry and thanks for your help

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for giving the feedback.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.