I am trying to log changes to a table, including deletes. The trigger is working effectively for INSERT and UPDATE, but does not capture the data from the row when I create a DELETE trigger. I have tried various trigger syntax methods to capture the data in a new "log" table, but I only seem to get the key field after the trigger fires.
My base table has only a few fields: ID (key), NAME, DESCRIPTION, CREATED_ON, UPDATED_ON.
On delete, I would like to capture the data that was deleted for record keeping and audit trails. Below is the latest iteration of my trigger define code:
create trigger ADDRESS_TYPES_TRIGGER_D BEFORE DELETE ON "MEDPORTAL"."MEDPORTAL_XS.data::ADDRESS_TYPES" REFERENCING OLD ROW AS thisRow FOR EACH ROW begin declare newId INT; declare deleteId INT := 131; select "MEDPORTAL"."MEDPORTAL_XS.data::Address_Types_Log_ID".NEXTVAL into newID from DUMMY; INSERT INTO "MEDPORTAL"."MEDPORTAL_XS.data::ADDRESS_TYPES_LOG" (ID, USERNAME, ACTION_ID, ADDRESS_TYPE_ID, NAME, DESCRIPTION, UPDATED_ON ) values( :newId, current_user, :deleteId, :THISROW.ID, :THISROW.NAME, :THISROW.DESCRIPTION, current_timestamp ); end
This code captures the newId from the sequence as the new table key. It also captures the USERNAME, ACTION_ID (coded to a delete message in another table), ADDRESS_TYPE_ID (THISROW.ID), and the current_timestamp. How can I capture the data in NAME and DESCRIPTION in the log table?
I have tried
create trigger ADDRESS_TYPES_TRIGGER_D AFTER DELETE ON "MEDPORTAL"."MEDPORTAL_XS.data::ADDRESS_TYPES" REFERENCING OLD ROW AS thisRow FOR EACH ROW
and
create trigger ADDRESS_TYPES_TRIGGER_D AFTER DELETE ON "MEDPORTAL"."MEDPORTAL_XS.data::ADDRESS_TYPES" FOR EACH ROW
But I cannot capture the data. I am on the AWS rev 70 image (1.0.70.386119)
Is the DELETE trigger capable of capturing the data?