Re: where cannot use alias name of column?

From: Giorgio Volpe <giorgio(dot)volpe(at)gtngroup(dot)it>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Postgresql <pgsql-general(at)postgresql(dot)org>
Subject: Re: where cannot use alias name of column?
Date: 2001-09-14 10:13:52
Message-ID: 3BA1D860.867DB5A4@gtngroup.it
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ian Barwick 2001-09-14 10:35:40 Re: get certain # of recs
Previous Message Thurstan R. McDougle 2001-09-14 09:34:36 Re: Query