From: Chris Anderson <cva@pobox.com>
To: pgsql-sql@postgresql.org
Subject: BEFORE UPDATE Triggers
Date: Thu, 28 Aug 2003 16:48:51 -0500
Message-ID: <69957C94-D9A1-11D7-8266-000393D3B384@pobox.com> (raw)
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
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: cva@pobox.com
Subject: Re: BEFORE UPDATE Triggers
In-Reply-To: <69957C94-D9A1-11D7-8266-000393D3B384@pobox.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