Re: Calculated fileds in pg

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Calculated fileds in pg
Date: 2002-11-24 18:14:57
Message-ID: 20021124101153.W42338-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Sun, 24 Nov 2002, Jean-Christian Imbeault wrote:

> Is it possible to set up a field during table creation to be a
> "calculated" field, i.e. the value is calculated from other values.
>
> For example:
>
> 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;
>
> If not should I be looking at implementing this with a view or maybe a
> trigger?

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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message javaholic 2002-11-24 18:16:49 How does postgres handle non literal string values
Previous Message Tom Lane 2002-11-24 17:40:25 Re: is backing up a live postgres enough?