Re: Re[2]: AW: [HACKERS] isnull() or is it?t - Mailing list pgsql-hackers

From jwieck@debis.com (Jan Wieck)
Subject Re: Re[2]: AW: [HACKERS] isnull() or is it?t
Date
Msg-id m0zoCfZ-000EBQC@orion.SAPserv.Hamburg.dsh.de
Whole thread Raw
In response to Re[2]: AW: [HACKERS] isnull() or is it?t  (Sferacarta Software <sferac@bo.nettuno.it>)
List pgsql-hackers
>
> If it is interesting to someone, we can partially emulate COALESCE
> right now as:
>
> create function coalesce(integer) returns integer as
> 'declare
>         nonullo alias for $1;
> begin
>      if nonullo then
>         return nonullo;
>      else
>         return 0;
>      end if;
>  end;
> ' language 'plpgsql';
> CREATE

    Pardon,  but  you  still  misuse the fact, that PL/pgSQL's IF
    expression is implicitly casted into a boolean.  That's  only
    possible for integer values.

    Please use

        IF nonullo ISNULL THEN
            RETURN 0;
        ELSE
            RETURN nonullo;
        END IF;

    instead,  because this would work for other types (like text,
    varchar etc.)  too.

    Since PL functions can be overloaded (like SQL functions), it
    would  be possible, but currently not that performant :-(, to
    create such a function for all types required.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#======================================== jwieck@debis.com (Jan Wieck) #

pgsql-hackers by date:

Previous
From: Frank Ridderbusch
Date:
Subject: subscribe
Next
From: Dan Gowin
Date:
Subject: RE: [HACKERS] PgAccess version 0.93 (for Unix and Windows) has be en released!