| From: | Wayne Conrad <wconrad(at)yagni(dot)com> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: SQL Rule |
| Date: | 2006-04-25 22:02:30 |
| Message-ID: | 20060425220230.GC3410@mail.yagni.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Kenneth Downs | 2006-04-25 22:16:13 | Re: SQL Rule |
| Previous Message | Oisin Glynn | 2006-04-25 21:41:05 | Re: SQL Rule |