From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Willy-Bas Loos <willybas(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: comparing NEW and OLD (any good this way?) |
Date: | 2009-07-23 11:45:36 |
Message-ID: | 162867790907230445xb71456ep65a6574c72043b37@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello
regards
Pavel Stehule
2009/7/23 Willy-Bas Loos <willybas(at)gmail(dot)com>:
> Hi,
>
> My colleage Geard Troost and I found a handy way of comparing OLD and
> NEW in a trigger function.
> Normally this does not work (if anyone can tell me why, that'd be
> great), but once you cast them to text, it does.
>
> Is there anything to say against this, or can i go ahead and recommend
> this to everyone who wants to check if anything changed before doing
> what their update triggers do?
>
> Cheers,
>
> WBL
>
> Here's the code:
>
> drop table test;
> create table test (id integer primary key, value integer);
> insert into test values (1,1);
> insert into test values (2,1);
> insert into test values (3,1);
> insert into test values (4,1);
> insert into test values (5,1);
> insert into test values (6,1);
>
> create or replace function bla() returns trigger as $$
> begin
> IF (NEW::TEXT = OLD::TEXT) THEN raise notice 'changed';
> END IF;
> return NEW;
> end
> $$
> language plpgsql;
>
> CREATE TRIGGER test_bla BEFORE UPDATE
> ON test FOR EACH ROW
> EXECUTE PROCEDURE public.bla();
>
> update test set value =NULL where id= 1;
> update test set value =NULL where id= 1;
>
> --
> "Patriotism is the conviction that your country is superior to all
> others because you were born in it." -- George Bernard Shaw
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
From | Date | Subject | |
---|---|---|---|
Next Message | leif | 2009-07-23 11:52:27 | ECPG Deallocate PREPARE statement - bug ? |
Previous Message | Willy-Bas Loos | 2009-07-23 11:40:45 | comparing NEW and OLD (any good this way?) |