Re: How change col name during query to use it in where clause

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How change col name during query to use it in where clause
Date: 2012-05-04 13:05:43
Message-ID: jo0k46$qhf$1@dough.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Carlos Mennens 2012-05-11 19:03:55 Finding Max Value in a Row
Previous Message Oliveiros d'Azevedo Cristina 2012-05-04 12:43:37 Re: How change col name during query to use it in where clause