Re: alias question - Mailing list pgsql-general

From Stephan Szabo
Subject Re: alias question
Date
Msg-id 20011214063137.K11758-100000@megazone23.bigpanda.com
Whole thread Raw
In response to alias question  (Ceasar <ocerda@hotmail.com>)
Responses Re: alias question
List pgsql-general
On Thu, 13 Dec 2001, Ceasar wrote:

> I was wondering if you could use an alias to do math calculations:  for
> example,
>
> select Bank1,
> (var1 + var2) as calc,
> calc*100 as var2
>
> From......
>
> I keep getting this message that says that calc is not in any of the
> tables in the From statement. Is it possible to use a alias (calc) to
> make further calculations?  If so, how?  Any help would be greatly
> appreciated.

I don't believe directly.  You can fake this somewhat by making a two
level query where the calculation is done in a subselect in from. It
looks however like the above is recursive, var2 depends on calc and calc
depends on var2 (or is var2 also a column name?)
Assuming it is a column, you should be able to do something like

select Bank1, calc, calc*100 as var2 from
 (select bank1, (var1+var2) as calc from ... ) ali;



pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Insert character codes in PosgreSQL with SQL command
Next
From: Francisco Reyes
Date:
Subject: Re: User rights across databases