Thread: Help! Record logging

Help! Record logging

From
"Edwin S. Ramirez"
Date:
Hello,
   I would like to setup a trigger to keep track of all changes done
onto the records of paticular tables.  Basically, there would be two
identical tables such as, 'medications' and 'medications_log', when a
user inserts, updates or deletes a record I would like a copy to be
inserted into the log table.  I already have audit information in the
medications table, so I only need to be able to copy the record over to
the log table.
   The only other difficulty is how do I let the trigger know the ID of
the user deleting the record?

Thanks,
Edwin S. Ramirez



Re: Help! Record logging

From
Richard Huxton
Date:
"Edwin S. Ramirez" wrote:
> 
> Hello,
> 
>     I would like to setup a trigger to keep track of all changes done
> onto the records of paticular tables.

Check my PostgreSQL Notes on techdocs.postgresql.org - there's an
example in there. Might be worth checking Roberto Mello's postgresql
cookbook too (same place).
>     The only other difficulty is how do I let the trigger know the ID of
> the user deleting the record?

SELECT CURRENT_USER sounds like what you want.

- Richard Huxton