From: | Hellmuth Vargas <hivs77(at)gmail(dot)com> |
---|---|
To: | Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> |
Cc: | Felipe Araoz Ramos <faraoz(at)gmail(dot)com>, PostgreSQL-foro <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Re: Select anidado dentro de Case when |
Date: | 2014-09-22 20:19:26 |
Message-ID: | CAN3Qy4ocCCiLffYBd_Lki9JW5QQEvKa2waedm=1L_XCffz9ETg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
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
From | Date | Subject | |
---|---|---|---|
Next Message | marcelo mendoza | 2014-09-23 12:48:31 | Failover para PostgreSQL |
Previous Message | Alvaro Herrera | 2014-09-22 19:17:03 | Re: Select anidado dentro de Case when |