X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 7A9A4D1B911 for ; Wed, 11 Feb 2004 01:17:13 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 84504-04 for ; Tue, 10 Feb 2004 21:17:13 -0400 (AST) Received: from srv02.shieldhost.com (srv02.shieldhost.com [66.98.168.13]) by svr1.postgresql.org (Postfix) with ESMTP id C9A04D1B8CE for ; Tue, 10 Feb 2004 21:17:08 -0400 (AST) Received: from DellLaptopDG (adsl-67-123-247-142.dsl.pltn13.pacbell.net [67.123.247.142]) (authenticated (0 bits)) by srv02.shieldhost.com (8.11.6/8.11.6) with ESMTP id i1B2Itm26459 for ; Tue, 10 Feb 2004 20:18:56 -0600 From: "David B" To: 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: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/101 X-Sequence-Number: 16792 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