pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David B <postgresql@thegatelys.com>
To: pgsql-sql@postgresql.org
Subject: Elegant way to monitor for changes in a trigger and migrate record to history table
Date: Tue, 10 Feb 2004 17:18:46 -0800
Message-ID: <GOEGKICPFOPNLIEIHGFJMEHHCHAA.postgresql@thegatelys.com> (raw)

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




view thread (2+ messages)  latest in thread

Message-ID: <GOEGKICPFOPNLIEIHGFJMEHHCHAA.postgresql@thegatelys.com>
Permalink:  ../GOEGKICPFOPNLIEIHGFJMEHHCHAA.postgresql@thegatelys.com/
Also on:    postgresql.org/message-id/GOEGKICPFOPNLIEIHGFJMEHHCHAA.postgresql@thegatelys.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: postgresql@thegatelys.com
  Subject: Re: Elegant way to monitor for changes in a trigger and migrate record to history table
  In-Reply-To: <GOEGKICPFOPNLIEIHGFJMEHHCHAA.postgresql@thegatelys.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox