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: Detecting changes to certain fields in 'before update' trigger functions
Date: 2008-12-01 15:18:51
Message-ID: ljuzkjok.fsf@vps203.linuxvps.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi list,

First steps in trigger functions and PL/pgSQL so please bear with me...

How can one detect changes to certain fields in before update trigger
functions?

IF (NEW.<column-name> != OLD.<column-name>) THEN ...

doesn't work, so obviously my understanding of the values of the
varriables NEW and OLD in before update trigger functions is wrong; I
had thought that OLD holds the record as it was before the update, and
that NEW holds the record as it is since the update (but before the
update has been committed)?

How should one go about detecting changes to certain fields in before
update trigger functions?

Any help/advice much appreciated.

Sebastian

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2008-12-01 15:27:48 Re: Trigger before delete does fire before, but delete doesn't not happen
Previous Message Tom Lane 2008-12-01 14:26:47 Re: Cannot open include file: 'nodes/nodes.h'