O'Reilly logo
  • Martin Castillo thinks this is interesting:

You don't generally want your users to be able to change audit logs, so only grant the managers the right to access these. If you plan to let users access the salary table directly, you should put a trigger on it for auditing


Cover of PostgreSQL Server Programming - Second Edition


Add TRIGGER to log information into another table. This can be done to all tables or to selected tables where user’s modify the data as part of a workflow.

In the example below, first he is creating the function that will analyze the type of modification being done on the table and then insert a record into the log table with the selected information. The second part is to create a TRIGGER and run the function on each row.