Re: BUG #1676: Statment order in rules - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #1676: Statment order in rules
Date
Msg-id 3985.1116517713@sss.pgh.pa.us
Whole thread Raw
In response to BUG #1676: Statment order in rules  ("Olleg Samoylov" <olleg@mipt.ru>)
Responses Re: BUG #1676: Statment order in rules  (Olleg Samoylov <olleg@mipt.ru>)
List pgsql-bugs
"Olleg Samoylov" <olleg@mipt.ru> writes:
> create rule delete_first as on delete to v do instead (delete from a where
> a=old.a;update c set c=c-1);

> delete from v where a=0;
> select * from a;
> -- 0 row, as expected :-)
> select * from c;
> -- 1, this is incorrect

This isn't a bug.  The DELETE causes the a=0 row to disappear from the
view, so the subsequent statement (which is implicitly conditional on
there being an a=0 row) doesn't do anything.  If it did do something,
then a "delete from v" that didn't delete any rows would still decrement
c, which is not what you want, eh?

            regards, tom lane

pgsql-bugs by date:

Previous
From: "Mohan, Ross"
Date:
Subject: Re: [PORTS] Bug Report with Postgres 7.4 on AIX 5.3
Next
From: Michael Fuhr
Date:
Subject: Re: BUG #1675: very slow work