X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 59389D1B8BB for ; Thu, 28 Aug 2003 21:49:22 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 09477-03 for ; Thu, 28 Aug 2003 18:48:53 -0300 (ADT) Received: from wink.pobox.com (wink.pobox.com [207.106.49.21]) by svr1.postgresql.org (Postfix) with ESMTP id 28857D1B8A9 for ; Thu, 28 Aug 2003 18:48:51 -0300 (ADT) Received: from texas.pobox.com (texas.pobox.com[64.49.223.111]) by wink.pobox.com (Postfix) with ESMTP id 958CF10131 for ; Thu, 28 Aug 2003 17:48:53 -0400 (EDT) Received: from pobox.com (unknown [67.64.77.89]) by texas.pobox.com (Postfix) with ESMTP id 1233745368 for ; Thu, 28 Aug 2003 17:48:53 -0400 (EDT) Date: Thu, 28 Aug 2003 16:48:51 -0500 Mime-Version: 1.0 (Apple Message framework v552) Content-Type: text/plain; charset=US-ASCII; format=flowed Subject: BEFORE UPDATE Triggers From: Chris Anderson To: pgsql-sql@postgresql.org Content-Transfer-Encoding: 7bit Message-Id: <69957C94-D9A1-11D7-8266-000393D3B384@pobox.com> X-Mailer: Apple Mail (2.552) X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/348 X-Sequence-Number: 14964 PostgreSQL Version: 7.2.3 Procedural Language: PL/pgSQL I have a table which contains a field for the user who last modified the record. Whenever a row in this table is updated, I want to have an UPDATE trigger do the following things: 1) Ensure the UPDATE query supplied a value for the action_user column 2) Log the record to an audit table so I can retrieve a change log Part 2 was trivial, however it seemed natural that if I had the following conditional in the trigger function: IF NEW.action_user ISNULL THEN ... I could raise an exception if that field was not supplied. (which would be the case if the function were triggered on an INSERT) Unfortunately it seems this is not the case. The NEW record contains values representing both the values explicitly provided with the UPDATE as well as the existing values which were not stipulated in the query. Is there any clever way around this limitation? It isn't the end of the world if I cannot verify this constraint in postgres, however it would have made it easier to ensure no one is making mistakes. Oh, and I am aware of the current_user variable. In my case this is useless as I don't care about the user at the database layer but rather at the application layer. Thanks in advance, cva