NULL values in PL/pgSQL functions input - Mailing list pgsql-general

From Alex Bolenok
Subject NULL values in PL/pgSQL functions input
Date
Msg-id 000901bffde8$284984d0$df02a8c0@artey.ru
Whole thread Raw
List pgsql-general
I wrote a function in PL/pgSQL that can accept NULL input values in some
variables. But I found that if I pass a single NULL value to the function,
all other values become NULL too. Here is the example:

CREATE FUNCTION fn_test(INT4, NUMERIC)
    RETURNS NUMERIC AS '
    BEGIN
        RAISE NOTICE
        ''%, %'', $1, $2;
        RETURN $2;
    END;
    ' LANGUAGE 'plpgsql';

peroon#= SELECT fn_test(1, 2.00);
NOTICE:  1, 2.000000
 fn_test
---------
       2
(1 row)
peroon#= SELECT fn_test(1, NULL);
NOTICE:  <NULL>, <NULL>
 fn_test
---------

(1 row)

Is it a bug?

I found no notice about it in documentation, so one more question:

Is there any workaround?

Alex Bolenok.


pgsql-general by date:

Previous
From: Peter Mount
Date:
Subject: RE: [HACKERS] pg_dump/restore to convert BLOBs to LZTEXT (optiona l!)
Next
From: Philip Warner
Date:
Subject: Strange strategy with COALESCE?