Sample Header Ad - 728x90

Postgresql: Trigger is not working at times

0 votes
2 answers
2851 views
I have a PostgreSQL trigger that is not firing sometimes, even though the status is always shown as "enabled". My trigger code is as follows: CREATE OR REPLACE FUNCTION audit_src_exhibit() RETURNS trigger AS $BODY$ BEGIN IF TG_OP = 'INSERT' then if new.audit_created_date is null THEN new.audit_created_date := current_timestamp; new.audit_created_by := session_user::text; end if; else if new.audit_modified_date is null THEN new.audit_modified_date := current_timestamp; new.audit_modified_by := session_user::text; end if; END IF; RETURN NEW; END; $BODY$ LANGUAGE plpgsql VOLATILE; CREATE TRIGGER audit_src_exhibit_tr BEFORE INSERT OR UPDATE ON FOR EACH ROW EXECUTE PROCEDURE audit_src_exhibit(); Is there any specific reason for this behaviour? Does my code show any signs of known issues which would result in triggers not firing? I find the audit columns populated as null when some insert happened today enter image description here
Asked by Arun (13 rep)
Feb 7, 2023, 09:43 AM
Last activity: Feb 7, 2023, 10:37 PM