Re: alias question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Cc: Ceasar <ocerda(at)hotmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: alias question
Date: 2001-12-14 16:01:51
Message-ID: 3969.1008345711@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> writes:
> 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;

This should work for saving typing, but be aware that it doesn't
necessarily save any computation. The planner will likely try to
collapse the two selects together, thus rewriting into the form

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

This shouldn't be an issue unless there is a hugely expensive function
or sub-select involved in the expression. In that case you might want
to use a temp table for the results of the lower select, and then do the
upper select from the temp table, so that the planner can't fold them
together.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Greg Sabino Mullane 2001-12-14 16:21:30 Re: Perl DBI, PostgreSQL performance question
Previous Message Tom Lane 2001-12-14 15:54:09 Re: Problem with OID wrap