Re: Detecting changes to certain fields in 'before update' trigger functions

From: Sebastian Tennant <sebyte(at)smolny(dot)plus(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Detecting changes to certain fields in 'before update' trigger functions
Date: 2008-12-01 16:35:36
Message-ID: 4p1nkg4n.fsf@vps203.linuxvps.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Quoth "Richard Broersma" <richard(dot)broersma(at)gmail(dot)com>:
> On Mon, Dec 1, 2008 at 7:18 AM, Sebastian Tennant
> <sebyte(at)smolny(dot)plus(dot)com> wrote:
>
>> IF (NEW.<column-name> != OLD.<column-name>) THEN ...
>
> The != operator doesn't work the way you might think when nulls are
> thrown into the mix. I asked a similar question a while back and was
> kindly pointed to the following syntax:
>
> IF( NEW.* IS DISTINCT FROM OLD.* ) THEN ...

That's it! Thanks very much Richard.

I sometimes think this kind of gotcha is purposely buried, or not
addressed at all, in order to force users to read the manual. I wasn't
planning on spending four hours doing just that, but now I suppose I'm
almost glad I did.

Sebastian

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrus 2008-12-01 17:04:50 Re: db backup script in gentoo
Previous Message Sebastian Tennant 2008-12-01 16:24:54 Re: Detecting changes to certain fields in 'before update' trigger functions