Re: Trigger help - updates to column data with null values

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Greg Fischer <greg(at)1stbyte(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Trigger help - updates to column data with null values
Date: 2010-03-03 04:07:30
Message-ID: 4B8DE082.7090303@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Greg Fischer wrote:
> Hello all!
> I do my best to read and google my way around issues, but I seem to be
> missing something. Probably simple too.
>
> So I have a trigger function, in which I'd like to check if a particular
> column has changed. It works great, unless either the OLD or NEW values
> are NULL. The purpose is to create a audit/log of the record. I prefer
> to only test for certain columns, not the whole table.
>
>
> CREATE OR REPLACE FUNCTION tr_employees_bu()
> RETURNS trigger AS
> $BODY$
> begin
> if (new.trainingdate <> old.trainingdate) then

Instead, try the test:

new.trainingdate IS DISTINCT FROM old.trainingdate

See the manual for 'IS DISTINCT FROM'.

--
Craig Ringer

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greg Fischer 2010-03-03 04:28:02 Re: Trigger help - updates to column data with null values
Previous Message Harvey, Allan AC 2010-03-03 03:59:12 Re: SQL Syntax - like FIELD and BITPATTERN = BITPATTERN?