Re: BUG #1098: Multiple ON INSERT rules not applied properly in the case of INSERT...SELECT

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: BUG #1098: Multiple ON INSERT rules not applied properly in the case of INSERT...SELECT
Дата
Msg-id 200403110855.16101.dev@archonet.com
обсуждение исходный текст
Ответ на BUG #1098: Multiple ON INSERT rules not applied properly in the case of INSERT...SELECT  ("PostgreSQL Bugs List" <pgsql-bugs@postgresql.org>)
Ответы Re: BUG #1098: Multiple ON INSERT rules not applied properly in the case of INSERT...SELECT  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
On Thursday 11 March 2004 06:45, PostgreSQL Bugs List wrote:
> The following bug has been logged online:
>
> Bug reference:      1098
> Logged by:          Tim Burgess
> Email address:      tim@queens.unimelb.edu.au

> Description:        Multiple ON INSERT rules not applied properly in the
> case of INSERT...SELECT

> Rules:
>     quips_transfer_from AS ON INSERT TO quips_transactions DO UPDATE
> users_quips SET balance = (users_quips.balance - new.amount) WHERE
> ((users_quips.username)::text = (new.user_from)::text)
>     quips_transfer_to AS ON INSERT TO quips_transactions DO UPDATE
> users_quips SET balance = (users_quips.balance + new.amount) WHERE
> ((users_quips.username)::text = (new.user_to)::text)

> insert into quips_transactions select 'frontoffice_quips', member_username,
> 10, now(), 'Free Print Credit' from group_members where groupname =
> 'freshers_04';
>
> And all the transactions are added, however the rules do not execute
> properly.  In our case, the quips_transfer_to rule worked fine - all the
> students had their balances credited.  However, the quips_transfer_from
> rule was only applied once (the frontoffice_quips user had their balance
> lowered by $10, not $2180 as they should have).

The rule should only be applied once. The rule system basically rewrites the
insert you supply into two other insert queries (from/to). It will not
generate one query for each row in quips_transactions (which is what you
want). You probably need a trigger on the transactions table that issues
separate queries for each row inserted.

--
  Richard Huxton
  Archonet Ltd

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: BUG #1097: Make failure
Следующее
От: "PostgreSQL Bugs List"
Дата:
Сообщение: BUG #1099: bad syntax error localisation