Re: Query - Mailing list pgsql-general

From raul.giucich@gmail.com
Subject Re: Query
Date
Msg-id 001485f5473404d7c7046abba839@google.com
Whole thread Raw
In response to Re: Query  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
List pgsql-general
O podrías escribir,

select campo1,
campo2,
campo1 - campo2 as campo_virtual,
campo3,
case when campo1 - campo2 = 1 then 5 else 0 end as segundo_campo_virtual
from tabla;

Saludos.
R.

On May 25, 2009 6:18am, Alban Hertroys <dalroi@solfertje.student.utwente.nl> wrote:
> On May 25, 2009, at 4:56 AM, marco santillan wrote:
>
>
>
>
> Hola a todos:
>
>
>
> Tengo la siguiente inquietud. En una consulta com la siguiente:
>
>
>
> select campo1,
>
> campo2,
>
> campo1 - campo2 as campo_virtual,
>
> campo3,
>
> case when campo_virtual = 1 then 5 else 0 end as segundo_campo_virtual
>
> from tabla;
>
>
>
> Esto lo puedo hacer en access sin ningun problema, pero en postgresql no reconoce el campo_virtual.
>
>
>
> ¿Es que postgresql no soporta esta consulta o existe algun otro metodo para lograr esta tecnica?
>
>
>
>
>
> Nota: (campo1 - campo2) en realidad es una compleja consulta que se usa varias veces lineas abajo.
>
>
>
>
>
>
> I believe you're asking whether it's not supported to reference column aliases further on in the query? You got that right, they don't get computed until the final stage of the query.
>
>
>
> A workaround is as follows:
>
>
>
> select campo1,
>
> campo2,
>
> campo_virtual,
>
> campo3,
>
> case when campo_virtual = 1 then 5 else 0 end as segundo_campo_virtual
>
> from (select *, campo1 - campo2 as campo_virtual from tabla) as tabla;
>
>
>
>
>
> Alban Hertroys
>
>
>
> --
>
> If you can't see the forest for the trees,
>
> cut the trees and you'll see there is no forest.
>
>
>
>
>
> !DSPAM:737,4a1a708910091961258073!
>
>
>
>
>
>
>
> --
>
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
>
> To make changes to your subscription:
>
> http://www.postgresql.org/mailpref/pgsql-general
>

pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: very large tables
Next
From: queries
Date:
Subject: Java Gui for Postgress