Re: Elegant way to monitor for changes in a trigger and migrate - Mailing list pgsql-sql

From Mark Gibson
Subject Re: Elegant way to monitor for changes in a trigger and migrate
Date
Msg-id 4029EA3C.5000509@cromwell.co.uk
Whole thread Raw
In response to Elegant way to monitor for changes in a trigger and migrate record to history table  ("David B" <postgresql@thegatelys.com>)
List pgsql-sql
David B wrote:

>Folks,
>
>Perhaps you can help....hell I'm sure you can!
>I want to monitor for changes in a table and migrate the OLD. record to
>audit table.
>
>Is there an elegant or generic way to do this so I can use across multiple
>tables with little change.
>  
>

You can use a rule to do this:

CREATE RULE cust_audit AS ON UPDATE OR DELETE TO cust DO INSERT INTO cust_hist SELECT OLD.*;

cust_hist should be identical to cust without a primary key or any 
constraints/foreign keys etc.

I'm currently working on an auditing system at present, and will be 
releasing it
soon if anyone is interested. It needs some cleaning up first, when I 
have time.

-- 
Mark Gibson <gibsonm |AT| cromwell |DOT| co |DOT| uk>
Web Developer & Database Admin
Cromwell Tools Ltd.
Leicester, England.



pgsql-sql by date:

Previous
From: Mona
Date:
Subject: unsubscribe
Next
From: Markus Bertheau
Date:
Subject: Re: Multiple outer join on same table