$$ BEGIN INSERT INTO deleted_records(table_name, record_id, deleted_at, transaction_id, data) VALUES(TG_TABLE_NAME, OLD.id, now() AT TIME ZONE 'utc', txid_current(), row_to_json(OLD)); RETURN NULL; END; $$ LANGUAGE plpgsql; CREATE TRIGGER store_deleted_table_name AFTER DELETE ON table_name FOR EACH ROW EXECUTE PROCEDURE store_deleted();