Re: caching subtotals: update vs sum -- aaugh!

Поиск
Список
Период
Сортировка
От Alaric B. Snell
Тема Re: caching subtotals: update vs sum -- aaugh!
Дата
Msg-id Pine.LNX.4.43.0201101247430.32663-100000@calvin.frontwire.com
обсуждение исходный текст
Ответ на caching subtotals: update vs sum -- aaugh!  (will trillich <will@serensoft.com>)
Список pgsql-general
On Thu, 10 Jan 2002, will trillich wrote:

> or should i settle for something like
>
>     select
>         item_id,
>         sum(bal) as bal,
>         sum(cost) as cost,
>         sum(charge) as charge
>     into
>         fooey
>     from
>         line_item
>     group by
>         item_id
>     ;
>     update invoice set
>         bal = fooey.bal,
>         cost = fooey.cost,
>         charge = fooey.charge
>     where fooey.item_id = id
>     ;
>     drop table fooey
>     ;
>
> ...? seems a bit of the old "long-way-around"... surely there's
> a way--

A stored procedure sounds the way ahead to me. DO it with a trigger if you
want updates to happen automagically whenever the line_items are changed:

http://www.postgresql.org/idocs/index.php?plpgsql-trigger.html
http://www.postgresql.org/idocs/index.php?sql-createtrigger.html

--
Alaric B. Snell, Developer
abs@frontwire.com


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

Предыдущее
От: Roman Gavrilov
Дата:
Сообщение: Re: select few fields as a single field
Следующее
От: "Alaric B. Snell"
Дата:
Сообщение: Re: Performance tips