BEFORE UPDATE Triggers - Mailing list pgsql-sql

From Chris Anderson
Subject BEFORE UPDATE Triggers
Date
Msg-id 69957C94-D9A1-11D7-8266-000393D3B384@pobox.com
Whole thread Raw
Responses Re: BEFORE UPDATE Triggers  (Jan Wieck <jan@black-lion.info>)
List pgsql-sql
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



pgsql-sql by date:

Previous
From: Joe Conway
Date:
Subject: Re: length of array
Next
From: Michael A Nachbaur
Date:
Subject: Forcing a trigger to run