Re: alias question - Mailing list pgsql-general

From Tom Lane
Subject Re: alias question
Date
Msg-id 3969.1008345711@sss.pgh.pa.us
Whole thread Raw
In response to Re: alias question  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List pgsql-general
Stephan Szabo <sszabo@megazone23.bigpanda.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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Problem with OID wrap
Next
From: "Greg Sabino Mullane"
Date:
Subject: Re: Perl DBI, PostgreSQL performance question