From: | Ron <ronljohnsonjr(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Referncing a calculated column in a select? |
Date: | 2019-09-12 20:35:56 |
Message-ID: | 9a55a78e-6a9d-b8a0-d9c8-f5a6fbc6fcea@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 9/12/19 2:23 PM, stan wrote:
> I am creating some views, that have columns with fairly complex calculations
> in them. The I want to do further calculations using the result of this
> calculation. Right now, I am just duplicating the first calculation in the
> select fro the 2nd calculated column. There must be a batter way to do
> this, right?
I must be misunderstanding you, because you can just do more of what you're
doing now.
Here's an example of doing some calculations in the creation of the view,
and then more calculations when selecting from the view:
test=# create table gargle (i integer, j integer);
CREATE TABLE
test=# create view v_gargle (i1, j1) as select i*2, j*3 from gargle;
CREATE VIEW
test=# select * from v_gargle;
i1 | j1
----+----
4 | 9
(1 row)
test=# select i1 - 3, j1 * 8 from v_gargle;
?column? | ?column?
----------+----------
1 | 72
--
Angular momentum makes the world go 'round.
From | Date | Subject | |
---|---|---|---|
Next Message | Peter J. Holzer | 2019-09-12 21:16:01 | Re: Referncing a calculated column in a select? |
Previous Message | Aaron Spike | 2019-09-12 20:03:25 | Re: Recover data from aborted transactions |