X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 0CB2FD1B47A for ; Thu, 15 Jan 2004 21:15:48 +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 68401-05 for ; Thu, 15 Jan 2004 17:15:18 -0400 (AST) Received: from mail.guest-tek.com (mail.guest-tek.com [66.11.76.195]) by svr1.postgresql.org (Postfix) with ESMTP id 85D7ED1C919 for ; Thu, 15 Jan 2004 17:15:15 -0400 (AST) Received: from TSDJKERKHOF (ptr-66-11-76-193.ptr.terago.ca [66.11.76.193]) by mail.guest-tek.com (8.11.6/8.11.6) with SMTP id i0FLBae08579 for ; Thu, 15 Jan 2004 14:11:37 -0700 From: "Jack Kerkhof" To: Subject: Trigger to identify which column(s) updated Date: Thu, 15 Jan 2004 14:15:01 -0700 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.6604 (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-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests=BAYES_30, MSGID_GOOD_EXCHANGE, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200401/151 X-Sequence-Number: 16544 Does anyone know how to write a trigger that would identify which columns have actually changed in an update (and then log them to an archive). I suspect that the function would look something like; CREATE FUNCTION FIND_CHANGED_COLUMNS() RETURNS OPAQUE AS ' BEGIN -- FOR EACH COLUMN IN THE RECORD: -- IF ( NEW COLUMNx <> OLD COLUMNx) -- LOG THE RECORD PRIMARY KEY, COLUMN NAME, OLD VALUE RETURN NEW; END; ' LANGUAGE 'plpgsql'; In other words - How might you parse, in general, old and new records to compare like columns? - How can you find out the primary key of a record? Thanks, Jack