Re: Calculated fileds in pg - Mailing list pgsql-general

From Jean-Christian Imbeault
Subject Re: Calculated fileds in pg
Date
Msg-id 3DE1793F.1010405@mega-bucks.co.jp
Whole thread Raw
In response to Re: Calculated fileds in pg  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Responses Re: Calculated fileds in pg
List pgsql-general
Stephan Szabo wrote:
>
>>
>>Table A:
>>
>>id   integer primary key,
>>B_id integer references B(id),
>>cost integer default 0
>>
>>Table B:
>>
>>id    integer primary key,
>>total integer -- select sum(cost) from A where B_id=id;
>
> I'd probably do B as a view if it was this simple, because writing the
> triggers for A sound to be problematic from a getting the concurrency
> right without potential deadlocks standpoint.

The tables are not *that* simple. Both have about 15 columns, *but*
there is just the one calculated column *and* it is as in the example,
just the sum of matching rows in the other table.

Here are the actual table schemas, would you still recommend a view? (I
know nothing about views so this would be my first attempt at them). And
you are right about the triggers being a problem for concurrency. I have
implemented the above as a trigger on every insert/update to Table B and
it is slow *and* I want to add other triggers but the concurrency aspect
  is a little problematic.

Jc


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Cluster problem
Next
From: Jean-Christian Imbeault
Date:
Subject: Re: Calculated fileds in pg