Elegant way to monitor for changes in a trigger and migrate record to history table - Mailing list pgsql-sql

From David B
Subject Elegant way to monitor for changes in a trigger and migrate record to history table
Date
Msg-id GOEGKICPFOPNLIEIHGFJMEHHCHAA.postgresql@thegatelys.com
Whole thread Raw
Responses Re: Elegant way to monitor for changes in a trigger and migrate
List pgsql-sql
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.

E.g.
IF TG_OP = 'UPDATE' THEN   INSERT INTO cust_hist ( col1, col2, col3, col4 ) VALUES ( OLD.col1,
OLD.col2, OLD.col4 ) ;
END IF ;

This hardly seems scalable for a table with 50-100 columns.
I'm thinking that perhaps there is a way to use RECORD or some such variable
to be able to do something like:

INSERT INTO cust_hist ( OLD.* ) ;

I guess something like this might also work:
INSERT INTO cust_hist SELECT * FROM cust WHERE cust_id = OLD.cust_id ;
But it strikes me as very very bad from a performance standpoint.

Would love to hear your thoughts.
-D

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.574 / Virus Database: 364 - Release Date: 1/29/2004



pgsql-sql by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Unique Constraint with foreign Key
Next
From: Mona
Date:
Subject: unsubscribe