by crescentfresh · 5y ago · 0 comments
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. select *
from affected_rows
With some additional columns that happen to be provided by postgres and/or a parameter to the SQL statement.