Re: Calculated fileds in pg
От | Jean-Christian Imbeault |
---|---|
Тема | Re: Calculated fileds in pg |
Дата | |
Msg-id | 3DE1793F.1010405@mega-bucks.co.jp обсуждение исходный текст |
Ответ на | Re: Calculated fileds in pg (Stephan Szabo <sszabo@megazone23.bigpanda.com>) |
Ответы |
Re: Calculated fileds in pg
|
Список | 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 по дате отправления: