Re: SQL Rule - Mailing list pgsql-general

From Wayne Conrad
Subject Re: SQL Rule
Date
Msg-id 20060425220230.GC3410@mail.yagni.com
Whole thread Raw
In response to SQL Rule  ("Bert" <clemens.bertschler@gmail.com>)
List 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 by date:

Previous
From: Wayne Conrad
Date:
Subject: "ERROR: out of memory" during pg_restore
Next
From: Kenneth Downs
Date:
Subject: Re: SQL Rule