Re: Calculated fileds in pg

From: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Calculated fileds in pg
Date: 2002-11-25 01:13:35
Message-ID: 3DE1793F.1010405@mega-bucks.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jean-Christian Imbeault 2002-11-25 01:31:50 Re: Calculated fileds in pg
Previous Message Tom Lane 2002-11-24 22:23:06 Re: Cluster problem