From: Andreas Kretschmer <akretschmer@spamfence.net>
To: pgsql-sql@postgresql.org
Subject: Re: newbie question
Date: Fri, 3 Mar 2006 11:51:36 +0100
Message-ID: <20060303105136.GA25541@KanotixBox> (raw)
In-Reply-To: <1141378989.5311.13.camel@geologia5.agora.ing.unipg.it>
References: <1141378989.5311.13.camel@geologia5.agora.ing.unipg.it>
ivan marchesini <marchesini@unipg.it> schrieb:
> Dear users..
> I have fastly created a table in a postgresql database..
> some columns where edited by hand (columns A, B, C), and some others
> (columns D, E, F) have been calculated as a result of mathematical
> equation (where the factors are the A, B, C columns)....
You should create a table with (a,b,c) and a view. Below a example.
test=# create table foo (a int, b int, c int);
CREATE TABLE
test=# create view foo_view as (select a,b,c,a*b as ab, a*c as ac, b*c as bc from foo);
CREATE VIEW
> now I simply need to change some values in the A, B, C columns and I
> would like to obtain the correct values in the D, E, F column...
> I know that this is a tipical problem of a spreadsheet but how can I
> solve it with a DBMS??
test=# insert into foo values (2,3,4);
INSERT 0 1
test=# select * from foo_view ;
a | b | c | ab | ac | bc
---+---+---+----+----+----
2 | 3 | 4 | 6 | 8 | 12
(1 row)
test=# update foo set a=3;
UPDATE 1
test=# select * from foo_view ;
a | b | c | ab | ac | bc
---+---+---+----+----+----
3 | 3 | 4 | 9 | 12 | 12
(1 row)
HTH, Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknow)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: akretschmer@spamfence.net
Subject: Re: newbie question
In-Reply-To: <20060303105136.GA25541@KanotixBox>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox