On Tue, Aug 10, 2010 at 09:12:07PM +0800, Colin Coe wrote:
> +
> +create or replace 
> +function decode(value anyelement, s1 anyelement, r1 anyelement, def 
> anyelement) returns anyelement 
> +as
> +$$
> +select case
> +  when
> +    $1=$2
> +  then
> +    $3
> +  else
> +    $4
> +end;
> +$$
> +LANGUAGE SQL;

I'm affraid we cannot just use = here:

SQL> select decode(null, null, 3, 4) from dual ;

DECODE(NULL,NULL,3,4)
---------------------
                    3


spaceschema=# select decode(null, null, 3, 4) from dual ;
 decode 
--------
      4
(1 row)

> +create or replace
> +function nvl(input integer, replace_with integer) returns integer
> +as $$
> +        SELECT COALESCE(NULLIF($1,0), $2);
> +$$
> +LANGUAGE SQL;

I'm affraid the nullif is not correct here:

SQL> select nvl(0, 123) from dual ;

NVL(0,123)
----------
         0

spaceschema=# select nvl(0, 123) from dual ;
 nvl 
-----
 123
(1 row)

So I'm not committing these two changes yet.

-- 
Jan Pazdziora
Principal Software Engineer, Satellite Engineering, Red Hat

_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to