Re: Determining if a table really changed in a trigger

Поиск
Список
Период
Сортировка
От Marcos Pegoraro
Тема Re: Determining if a table really changed in a trigger
Дата
Msg-id CAB-JLwaABhUOttAKiioU+p-knaJV8SWwb8xEXo17Z+OHfp+06g@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Determining if a table really changed in a trigger  (Mitar <mmitar@gmail.com>)
Ответы Re: Determining if a table really changed in a trigger  (Mitar <mmitar@gmail.com>)
Список pgsql-general
Oh, very interesting. I thought that this is not possible because WHEN
condition on triggers does not have NEW and OLD. But this is a very
cool way to combine rules with triggers, where a rule can still
operate by row.

That is not true
 
create table test(i integer);
create function test_old_new() returns trigger language plpgsql as $$
begin
   raise notice '% - %', old.i, new.i;
   return new;
end;$$;
CREATE TRIGGER testvalue BEFORE UPDATE OF i ON test FOR EACH ROW WHEN (((new.i)::integer = 5::integer)) EXECUTE PROCEDURE test_old_new();
> insert into test values(4)
1 row affected in 52 ms
> update test set i = 6
1 row affected in 93 ms
> update test set i = 5
6 - 5 ->raise notice of procedure test_old_new was called only when new.i = 5
1 row affected in 48 ms 

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

Предыдущее
От: Jayadevan M
Дата:
Сообщение: Re: String comparison fails for some cases after migration
Следующее
От: Tore Halvorsen
Дата:
Сообщение: pg_dump and pg_restore and foreign keys