pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedHow change col name during query to use it in where clause
4+ messages / 4 participants
[nested] [flat]
* How change col name during query to use it in where clause
@ 2012-05-04 10:25 Marcel Ruff <mr@marcelruff.info>
0 siblings, 3 replies; 4+ messages in thread
From: Marcel Ruff @ 2012-05-04 10:25 UTC (permalink / raw)
To: pgsql-sql
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 ...
Thank you
Marcel
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: How change col name during query to use it in where clause
@ 2012-05-04 12:40 Andreas Kretschmer <andreas@a-kretschmer.de>
parent: Marcel Ruff <mr@marcelruff.info>
2 siblings, 0 replies; 4+ messages in thread
From: Andreas Kretschmer @ 2012-05-04 12:40 UTC (permalink / raw)
To: Marcel Ruff <mr@marcelruff.info>; pgsql-sql
Marcel Ruff <mr@marcelruff.info> hat am 4. Mai 2012 um 12:25 geschrieben:
> Hi,
>
> is an alias name not usable in the where clause?
Exactly.
Andreas
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: How change col name during query to use it in where clause
@ 2012-05-04 12:43 Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
parent: Marcel Ruff <mr@marcelruff.info>
2 siblings, 0 replies; 4+ messages in thread
From: Oliveiros d'Azevedo Cristina @ 2012-05-04 12:43 UTC (permalink / raw)
To: Marcel Ruff <mr@marcelruff.info>; pgsql-sql
I'm affraid
you can't.
AFAIK,
WHERE clause is processed before the SELECT output expressions
Best,
Oliveiros
----- Original Message -----
From: "Marcel Ruff" <mr@marcelruff.info>
To: <pgsql-sql@postgresql.org>
Sent: Friday, May 04, 2012 11:25 AM
Subject: [SQL] How change col name during query to use it in where clause
> 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 ...
>
> Thank you
> Marcel
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: How change col name during query to use it in where clause
@ 2012-05-04 13:05 Thomas Kellerer <spam_eater@gmx.net>
parent: Marcel Ruff <mr@marcelruff.info>
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Kellerer @ 2012-05-04 13:05 UTC (permalink / raw)
To: 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;
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2012-05-04 13:05 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-05-04 10:25 How change col name during query to use it in where clause Marcel Ruff <mr@marcelruff.info>
2012-05-04 12:40 ` Andreas Kretschmer <andreas@a-kretschmer.de>
2012-05-04 12:43 ` Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
2012-05-04 13:05 ` Thomas Kellerer <spam_eater@gmx.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox