Re: Select anidado dentro de Case when

From: eduardo reyes <allcomsystem(at)gmail(dot)com>
To:
Cc: PostgreSQL-foro <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: Select anidado dentro de Case when
Date: 2014-09-23 13:38:56
Message-ID: CAEgdABW6Ac6gpqUsYkv3nA-ZY8L6-PCqvcvVHgmdEqBR4KbdOQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Saludos.

yo lo haria menos complicado:

begin
return query

select c1,c2 from tabla where c1='ME' and c2='2013'
AND $1='1'
UNION ALL
select c1,c2 from tabla where c1='ME'
AND $1 !='1'

end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;

El 22 de septiembre de 2014, 16:19, Hellmuth Vargas <hivs77(at)gmail(dot)com>
escribió:

>
> Hola Lista
>
> Y asi:
>
> begin
>
> return query
> select c1,c2 from tabla where c1='ME' and case $1 when '1' then c2='2013'
> else true end;
> end;
>
>
>
>
> El 22 de septiembre de 2014, 14:17, Alvaro Herrera<
> alvherre(at)2ndquadrant(dot)com> escribió:
>
> Felipe Araoz Ramos escribió:
>> > Buen dias amigos del foro
>> >
>> > Estoy queriendo hacer mas flexible mi función y quiero hacer algo como
>> > esto; anidar select dentro de un bloque case,... es posible hacer esto
>> >
>> > begin
>> > return query
>> > case when $1='1' then
>> > select c1,c2 from tabla where c1='ME' and c2='2013'
>> > else
>> > select c1,c2 from tabla where c1='ME'
>> > end;
>> > end;
>>
>> Me parece que no debería funcionar, pero sí lo siguiente:
>>
>> begin
>> case $1 when '1' then
>> return query
>> select c1,c2 from tabla where c1='ME' and c2='2013';
>> else
>> return query
>> select c1,c2 from tabla where c1='ME';
>> end case;
>> end;
>>
>> Nota que el CASE que se está usando aquí no es el de SQL, sino el de
>> plpgsql, y por eso tienes que terminarlo con END CASE en lugar de END, y
>> la razón por la que tienes que poner los ; al final de cada RETURN
>> (además de poner el RETURN en cada brazo en lugar de uno solo).
>>
>> Mira en
>> www.postgresql.org/docs/9.3/static/plpgsql-control-structures.html
>>
>> --
>> Álvaro Herrera http://www.2ndQuadrant.com/
>> PostgreSQL Development, 24x7 Support, Training & Services
>>
>> -
>> Enviado a la lista de correo pgsql-es-ayuda (
>> pgsql-es-ayuda(at)postgresql(dot)org)
>> Para cambiar tu suscripción:
>> http://www.postgresql.org/mailpref/pgsql-es-ayuda
>>
>
>
>
> --
> Cordialmente,
>
> Ing. Hellmuth I. Vargas S.
> Esp. Telemática y Negocios por Internet
> Oracle Database 10g Administrator Certified Associate
> PostgreSQL DBA
>
>

--
*Ing. Eduardo Reyes*
Analista Programador.
(809) 607-1961
ereyes(at)h-rivera(dot)com

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Gilberto Castillo 2014-09-23 13:52:59 Re: Failover para PostgreSQL
Previous Message raul andrez gutierrez alejo 2014-09-23 13:34:01 Re: Failover para PostgreSQL