Re: Implementar IIf

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Jaime Casanova <jcasanov(at)systemguards(dot)com(dot)ec>
Cc: ROBWARE RUIZ <robware(dot)ruiz(at)gmail(dot)com>, pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: Implementar IIf
Date: 2008-09-07 18:02:12
Message-ID: 20080907180212.GB3975@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Jaime Casanova escribió:

> la funcion iif en plsql es bastante simple:
>
> create function iif(boolean, int, int) returns int as$$
> select case $1 when true then $2 else $3 end;
> $$ language sql;

Esta definicion asume que los valores a retornar son enteros ... mejor
asi:

create function iif(boolean, anyelement, anyelement) returns int as$$
select case $1 when true then $2 else $3 end;
$$ language sql;

Eso debería funcionar para cualquier tipo escalar; no va a funcionar
para arrays. Quizás esto funcione:

create function iif(boolean, any, any) returns int as$$
select case $1 when true then $2 else $3 end;
$$ language sql;

pero no estoy seguro. En el peor de los casos podrías definir dos
funciones, una que sea (bool, anyelement, anyelement) y otra que sea
(bool, anyarray, anyarray). (Habría que ver que hacer con los enums)

--
Alvaro Herrera http://www.amazon.com/gp/registry/5ZYLFMCVHXC
"If it wasn't for my companion, I believe I'd be having
the time of my life" (John Dunbar)

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Guido Barosio 2008-09-07 19:09:00 Re: Funcion IIf()
Previous Message Jaime Casanova 2008-09-07 17:57:50 Re: Implementar IIf