Re: SQL Rule

Поиск
Список
Период
Сортировка
От Wayne Conrad
Тема Re: SQL Rule
Дата
Msg-id 20060425220230.GC3410@mail.yagni.com
обсуждение исходный текст
Ответ на SQL Rule  ("Bert" <clemens.bertschler@gmail.com>)
Список pgsql-general
On Tue, Apr 25, 2006 at 02:27:23PM -0700, Bert wrote:
> I have a table construction like the one seen below, when i am updating
> or inserting i get a recurion, logical. But how to manage it that the
> rule is just doing it one time. Or is it possible to do the sum of a
> and b in an other way?
> ...
Bert,

(This is a resend to the list; I sent my reply privately by mistake).

Have you considered using a view to do the sums on the fly?  This
avoids all kinds of denormalization troubles (the sum can never be
incorrect):

wayne=# create table test (a int, b int);
CREATE TABLE
wayne=# create view test_sum as select *, a + b as c from test;
CREATE VIEW
wayne=# insert into test (a, b) values (1, 2);
INSERT 0 1
wayne=# insert into test (a, b) values (3, 4);
INSERT 0 1
wayne=# select * from test_sum;
 a | b | c
---+---+---
 1 | 2 | 3
 3 | 4 | 7
(2 rows)

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

Предыдущее
От: Wayne Conrad
Дата:
Сообщение: "ERROR: out of memory" during pg_restore
Следующее
От: Kenneth Downs
Дата:
Сообщение: Re: SQL Rule