Trigger help - updates to column data with null values

Поиск
Список
Период
Сортировка
От Greg Fischer
Тема Trigger help - updates to column data with null values
Дата
Msg-id c16a72fa1003021720h7d5383a9v6500de63c197becb@mail.gmail.com
обсуждение исходный текст
Ответы Re: Trigger help - updates to column data with null values  (Craig Ringer <craig@postnewspapers.com.au>)
Список pgsql-general
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
insert into log_employees (employeeid,
source, datecreated,
createdby, oldvalue,newvalue)
values
(old.employeeid,'trainingdate',
now(),new.updatedby,
cast(old.codetrainingdate as varchar),
cast(new.codetrainingdate as varchar));
end if;
end;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE
  COST 100;

I tried playing with "coalesce" and "nullif" but didn't get anywhere with those.  I think the "if" expression is not right.

Thanks for any help!

Greg Fischer
www.1stbyte.com

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

Предыдущее
От: Ozz Nixon
Дата:
Сообщение: Re: [SOLVED] SQL Syntax - like FIELD and BITPATTERN = BITPATTERN?
Следующее
От: Craig Ringer
Дата:
Сообщение: Re: Trigger help - updates to column data with null values