Re: conditional rule not applied

From: Seb <spluque(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: conditional rule not applied
Date: 2010-01-09 06:20:17
Message-ID: 87iqbber4u.fsf@kolob.sebmags.homelinux.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 7 Jan 2010 21:04:45 -0700,
Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com> wrote:

> On Wed, Dec 30, 2009 at 6:39 PM, Seb <spluque(at)gmail(dot)com> wrote:
>> CREATE RULE footwear_nothing_upd AS    ON UPDATE TO footwear DO
>> INSTEAD NOTHING; CREATE RULE footwear_newshoelaces_upd AS    ON
>> UPDATE TO footwear    WHERE NEW.sl_name <> OLD.sl_name AND
>> OLD.sl_name IS NULL    DO INSERT INTO shoelaces (sh_id, sl_name)  
>>  VALUES(NEW.sh_id, NEW.sl_name);

> Isn't that first rule gonna always fire and make the second one a
> NOOP?

No, the second is an implied ALSO, so it gets added to the DO INSTEAD
NOTHING. This is actually the approach recommended in the man page for
CREATE RULE where the reasons for doing that are described. The problem
with this is that it always displays the message "UPDATE 0" when in fact
the second rule may have also been applied with the INSERT. I posted
this question to the postgresql.sql NG, where some discussion ensued.

--
Seb

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Anisha Kaul 2010-01-09 09:58:58 pgsql2shp usage
Previous Message Erik Jones 2010-01-09 00:55:13 Re: WAL Log Shipping - Warm Standby not working under 8.3.7