Re: where cannot use alias name of column? - Mailing list pgsql-general

From Giorgio Volpe
Subject Re: where cannot use alias name of column?
Date
Msg-id 3BA1D860.867DB5A4@gtngroup.it
Whole thread Raw
In response to Re: where cannot use alias name of column?  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-general
Peter Eisentraut wrote:

> Giorgio Volpe writes:
>
> > May be it's my ignorance about sql ...
> > but why cannot i use alias name of a column in a where clause?
> >
> > # select key as cc from mytable where cc > 0;
> > ERROR:  Attribute 'cc' not found
>
>  If you want to use an alias in the WHERE clause you have to
> introduce it in the FROM clause, such as:
>
> SELECT * FROM mytable AS myalias (xx, yy, zz) WHERE zz > 0;
>
> This may or may not be actually useful in your case.
>

ok & thanks ... actually in my case does not help
i would like to rename a value from an expression so to use it in the where
clause without rewriting the expression!
... for example!

    select date_part('month',my_date) as month from my_table where  month =
3;

it would be very nice with very complex expressions! (also avoiding
postgresql to evaluate them twice or more times!)
is there a workaround for this?

--

    Giorgio

-----------------------------------------




pgsql-general by date:

Previous
From: "Thurstan R. McDougle"
Date:
Subject: Re: Query
Next
From: "Thurstan R. McDougle"
Date:
Subject: Re: count of occurences PLUS optimisation