Re: How change col name during query to use it in where clause - Mailing list pgsql-sql

From Thomas Kellerer
Subject Re: How change col name during query to use it in where clause
Date
Msg-id jo0k46$qhf$1@dough.gmane.org
Whole thread Raw
In response to How change col name during query to use it in where clause  (Marcel Ruff <mr@marcelruff.info>)
List pgsql-sql
Marcel Ruff, 04.05.2012 12:25:
> Hi,
>
> is an alias name not usable in the where clause?
>
> select EXTRACT(day from enddate::TIMESTAMP - old_enddate::TIMESTAMP) AS TAGE from account_h where TAGE>5;
> ERROR: column "tage" does not exist
> LINE 1: ... TAGE>5 ...

You need to wrap the query:

select *
from (   select EXTRACT(day from enddate::TIMESTAMP - old_enddate::TIMESTAMP) AS TAGE   from account_h
) t
where TAGE > 5;





pgsql-sql by date:

Previous
From: Andreas Kretschmer
Date:
Subject: Re: How change col name during query to use it in where clause
Next
From: Carlos Mennens
Date:
Subject: Finding Max Value in a Row