CASE Select, referring to selected value

From: "Nick Riemondi" <nick(at)outerscape(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: CASE Select, referring to selected value
Date: 2002-07-01 22:00:18
Message-ID: fc.009863ef00088e10009863ef00088e10.88e1e@fc2.outerscape.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi!
I've got 2 date fields in table which constitute a term. On select I'm
calculating that term, BUT I can't figure out how to refer to it in the
sql - or if it's possible. I'd like to be able to use the case returned
value for order, comparing, etc. Here's an example:

select case when (current_date > available) then ((end_date -
current_date) / 30)
when (current_date < available) then ((end_date - available) /
30)
end
from listing

This yields something along the line of:

case
------
2
39
11
64
...

which is great. Now, I'd like to be able to do this for example:

select case when (current_date > available) then ((end_date -
current_date) / 30)
when (current_date < available) then ((end_date - available) /
30)
end
from listing
where case > 4

which yields:
ERROR: parser: parse error at or near ">"

Does anyone know how I could accomplish this?

Thanks in Advance!
Nick

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Ferenc Engard 2002-07-01 23:37:08 Re: pl/pgsql capabilities?
Previous Message Jan Wieck 2002-07-01 18:13:34 Re: pg_restore cannot restore function