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

Поиск
Список
Период
Сортировка
От Craig Ringer
Тема Re: Trigger help - updates to column data with null values
Дата
Msg-id 4B8DE082.7090303@postnewspapers.com.au
обсуждение исходный текст
Ответ на Trigger help - updates to column data with null values  (Greg Fischer <greg@1stbyte.com>)
Ответы Re: Trigger help - updates to column data with null values  (Greg Fischer <greg@1stbyte.com>)
Список 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

В списке pgsql-general по дате отправления:

Предыдущее
От: Greg Fischer
Дата:
Сообщение: Trigger help - updates to column data with null values
Следующее
От: Greg Fischer
Дата:
Сообщение: Re: Trigger help - updates to column data with null values