Re: comparing NEW and OLD (any good this way?) - Mailing list pgsql-general

From Pavel Stehule
Subject Re: comparing NEW and OLD (any good this way?)
Date
Msg-id 162867790907230445xb71456ep65a6574c72043b37@mail.gmail.com
Whole thread Raw
In response to comparing NEW and OLD (any good this way?)  (Willy-Bas Loos <willybas@gmail.com>)
Responses Re: comparing NEW and OLD (any good this way?)
Re: comparing NEW and OLD (any good this way?)
Re: comparing NEW and OLD (any good this way?)
Re: comparing NEW and OLD (any good this way?)
List pgsql-general
Hello

http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks#Fast_compare_variables_NEW_and_OLD_in_trigger.27s_body

regards
Pavel Stehule

2009/7/23 Willy-Bas Loos <willybas@gmail.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@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

pgsql-general by date:

Previous
From: Marcin Gon
Date:
Subject: ERROR: unexpected data beyond EOF in block of relation "RelationName"
Next
From: leif@crysberg.dk
Date:
Subject: ECPG Deallocate PREPARE statement - bug ?