From: Alvaro Herrera <alvherre@dcc.uchile.cl>
To: Martín Marqués <martin@bugs.unl.edu.ar>
Cc: pgsql-sql@postgresql.org
Subject: Re: CASE not working
Date: Mon, 21 Mar 2005 10:29:31 -0400
Message-ID: <20050321142931.GA11919@dcc.uchile.cl> (raw)
In-Reply-To: <200503211118.39223.martin@bugs.unl.edu.ar>
References: <200503211118.39223.martin@bugs.unl.edu.ar>
On Mon, Mar 21, 2005 at 11:18:38AM -0300, Martín Marqués wrote:
Hey Martin,
> I have this query which has a CASE in the middle to give me special results.
> The problem is that it doesn't interpret my columns as it should.
>
> Here is the porblem:
>
> siprebi=> SELECT getvencimientosancion(190) AS vence, (SELECT codigo FROM
> sanciones WHERE persona = (SELECT persona FROM usuarios WHERE codigo = 190)
> ORDER BY femodif DESC LIMIT 1) AS sancion_original, CASE WHEN vence>=now()
> THEN 1 ELSE 0 END AS sancionado;
> ERROR: no existe la columna "vence"
The problem is that the "vence" alias is not available at the time the
CASE is evaluated. You need to use the getvencimientosancion()
function, or put it in a subselect in case it's expensive to compute (or
has side effects).
--
Alvaro Herrera (<alvherre[@]dcc.uchile.cl>)
"Java is clearly an example of a money oriented programming" (A. Stepanov)
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: alvherre@dcc.uchile.cl, martin@bugs.unl.edu.ar
Subject: Re: CASE not working
In-Reply-To: <20050321142931.GA11919@dcc.uchile.cl>
* 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