Re: BUG #1447: Sometimes rules don't work

From: Olleg Samoylov <olleg(at)mipt(dot)ru>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1447: Sometimes rules don't work
Date: 2005-01-31 08:04:49
Message-ID: 41FDE6A1.90609@mipt.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Tom Lane wrote:
> "Olleg Samoylov" <olleg(at)mipt(dot)ru> writes:
>
>>create rule history_i as on insert to history do (update abonent set
>>money=money+new.money where abonent=new.abonent);
>
>>insert into history (abonent,money) select abonent,-(money.money+5) as pay
>>from
>> ( select abonent,sum(money) as money from history where money<0 group by
>>abonent) money
>> where money.money+5>0;

> What happens in the above is that the "new.money" placeholder is
> replaced by the subselect from the INSERT command, and since the rule
> fires after the insert itself is done, you get different results from
> the second evaluation of the subselect.

IMHO, this is incorrect.

> You should be using a trigger for this sort of thing, not a rule.
> Rules have their uses, but propagating copies of data from one place
> to another is generally not one of them.

If you don't plan to fix this, this "feature" must be well documented.

--
Olleg

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Donald Fraser 2005-01-31 09:10:48 postgresql-7.4.6-2PGDG.src.rpm broken for Redhat 7,8 or 9
Previous Message Larry Rosenman 2005-01-31 03:49:43 Re: [BUGS] Bug in create operator and/or initdb