Re: Problem with aliasing

From: Greg Stark <gsstark(at)mit(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Problem with aliasing
Date: 2003-02-21 13:21:47
Message-ID: 87bs1522hg.fsf@stark.dyndns.tv
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp> writes:

> TAL=# select max(req_del_date1, req_del_date2, req_del_date3) as ma1 from
> invoices where ma1 <= now();
> ERROR: Attribute "ma1" not found
>
> What is wrong with my syntax?

Try either of:

SELECT max(req1, req2, req3) AS max FROM invoices WHERE max(req1, req2, req3) <= now()
SELECT * from (select max(req1, req2, req3) AS max FROM invoices) WHERE max <= now()

Whichever seems clearer to you, I think postgres actually runs the two the
same way. Note, you should mark your function immutable so postgres knows it
can optimize the second case into the first.

--
greg

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Sullivan 2003-02-21 13:23:31 Re: Authentication to run pg_dump automatically
Previous Message Karel Zak 2003-02-21 11:17:08 Re: type casting a subselect as an interval