Trigger using 'if NEW = OLD'

From: Colin Fox <cfox(at)cfconsulting(dot)ca>
To: pgsql-general(at)postgresql(dot)org
Subject: Trigger using 'if NEW = OLD'
Date: 2004-03-03 12:39:38
Message-ID: pan.2004.03.03.12.39.36.226411@cfconsulting.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I've got a trigger function that gets executed after an insert or an
update. It basically just creates a copy of the row in a history table.

However, there are cases when a row will be updated to be the same as it
was - in other words, no change. In these cases, the history is useless
and taking up space.

So I want the procedure to start with:

IF NEW = OLD then
return NEW;
end if;

thus exiting before the history record gets created.

However, if I do that, I get:
WARNING: line 6 at if
ERROR: NEW used in non-rule query

What is a non-rule query? :(

I'm led to believe by the documentation and other postings I've seen
archived on the web that this should be possible.

Am I doing something wrong, or do I have to do it the long way around
(field by field comparison)?

Thanks,
cf

--
Colin Fox
President
CF Consulting Inc.

Browse pgsql-general by date

  From Date Subject
Next Message Lincoln Yeoh 2004-03-03 13:16:27 Re: Moving from MySQL to PGSQL....some questions
Previous Message bsimon 2004-03-03 12:35:37 SPI memory managment issue