|
|
|
|
|
by crescentfresh
1696 days ago
|
|
Audit tables are awesome, this technique is great. We had one additional requirement that got us away from using a trigger for this: we wanted to know what user (in the application) caused the change. So we moved the logic of "insert into audit_table" into the application code itself using a CTE, roughly translated as: with affected_rows as (
insert/update/delete into/from ...
returning *
)
insert into my_audit_table
select @op, current_timestamp, @userinfo, * from affected_rows
where @op is bound to one of "insert", "update" or "delete" and @userinfo is the user(name|id|various|etc) of the user that caused the change. |
|