Re: Referncing a calculated column in a select? - Mailing list pgsql-general

From Ron
Subject Re: Referncing a calculated column in a select?
Date
Msg-id 9a55a78e-6a9d-b8a0-d9c8-f5a6fbc6fcea@gmail.com
Whole thread Raw
In response to Referncing a calculated column in a select?  (stan <stanb@panix.com>)
Responses Re: Referncing a calculated column in a select?
List 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.



pgsql-general by date:

Previous
From: Aaron Spike
Date:
Subject: Re: Recover data from aborted transactions
Next
From: "Peter J. Holzer"
Date:
Subject: Re: Referncing a calculated column in a select?