pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Achilleus Mantzios <achill@matrix.gatewaynet.com>
To: Nick Riemondi <nick@outerscape.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: CASE Select, referring to selected value
Date: Tue, 2 Jul 2002 15:16:53 +0300 (EEST)
Message-ID: <Pine.LNX.4.44.0207021516290.7811-100000@matrix.gatewaynet.com> (raw)
In-Reply-To: <fc.009863ef00088e10009863ef00088e10.88e1e@fc2.outerscape.net>

On Mon, 1 Jul 2002, Nick Riemondi wrote:

Just rewrite your case statement in the where clause.

> 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
> 
> 
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
> 
> 

-- 
Achilleus Mantzios
S/W Engineer
IT dept
Dynacom Tankers Mngmt
tel:    +30-10-8981112
fax:    +30-10-8981877
email:  achill@matrix.gatewaynet.com
        mantzios@softlab.ece.ntua.gr






view thread (4+ messages)  latest in thread

Message-ID: <Pine.LNX.4.44.0207021516290.7811-100000@matrix.gatewaynet.com>
Permalink:  ../Pine.LNX.4.44.0207021516290.7811-100000@matrix.gatewaynet.com/
Also on:    postgresql.org/message-id/Pine.LNX.4.44.0207021516290.7811-100000@matrix.gatewaynet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: achill@matrix.gatewaynet.com, nick@outerscape.net
  Subject: Re: CASE Select, referring to selected value
  In-Reply-To: <Pine.LNX.4.44.0207021516290.7811-100000@matrix.gatewaynet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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