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 <table>
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 am getting the audit columns as empty even though some insert and update happened today
audit_created_date
can be NULL if the operation is anUPDATE
.