Re: Updating

From: Bob Pawley <rjpawley(at)shaw(dot)ca>
To: Adrian Klaver <aklaver(at)comcast(dot)net>, pgsql-general(at)postgresql(dot)org
Cc: Daniel Verite <daniel(at)manitou-mail(dot)org>
Subject: Re: Updating
Date: 2008-03-17 17:37:22
Message-ID: 01cb01c88855$8f1a6ad0$6401a8c0@owner
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am attempting to use the following code but I get -
"ERROR: NEW used in query that is not in a rule".

This implies that I create a rule for NEW and OLD (which I haven't needed
before).

Could someone point me to the proper synatx for such a rule?

BTW I noticed that Adrian used != . Is this symbol the same as <> ?

Bob
----- Original Message -----
From: "Adrian Klaver" <aklaver(at)comcast(dot)net>
To: <pgsql-general(at)postgresql(dot)org>
Cc: "Daniel Verite" <daniel(at)manitou-mail(dot)org>; "Bob Pawley"
<rjpawley(at)shaw(dot)ca>
Sent: Monday, March 17, 2008 7:16 AM
Subject: Re: [GENERAL] Updating

> On Monday 17 March 2008 4:54 am, Daniel Verite wrote:
>> Adrian Klaver wrote:
>> > CREATE FUNCTION foo() RETURNS trigger AS
>> > $Body$
>> > BEGIN
>> > IF NEW.colname != OLD.colname THEN
>> > ..."Do something"..;
>> > RETURN whatever;
>> > ELSE
>> > RETURN NEW:
>> > END IF;
>> > END;
>> > $Body$ LANGUAGE plpgsql;
>>
>> Beware that the "Do something" code path will not be taken when the
>> column goes from NULL to non-NULL or non-NULL to NULL.
>>
>> In the general case where the column is nullable, better use "IS
>> DISTINCT FROM" instead of inequality:
>> IF NEW.colname IS DISTINCT FROM OLD.colname
>>
>> Best regards,
>> --
>> Daniel
>> PostgreSQL-powered mail user agent and storage:
>> http://www.manitou-mail.org
>
> Thanks for the heads up. This is a case I usually only remember when I
> start
> testing the function.
> --
> Adrian Klaver
> aklaver(at)comcast(dot)net
>
> --
> 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message postgre 2008-03-17 17:57:41 Re: [GENERAL] large object import
Previous Message Tom Lane 2008-03-17 17:29:59 Re: Catch-22