PL/Perl tries to handle an "undef" result from a Perl function (which
should convert to a SQL NULL) with code like so:

    /* XXX is this the approved way to check for an undef result? */
    if (perlret == &PL_sv_undef)
    {
        retval = (Datum) 0;
        fcinfo->isnull = true;
    }
    else
    {
	// handle non-null result
    }

But I find that it doesn't work, at least not on RH Linux 7.2 with
perl 5.6.0.  The if-test fails to notice undef results.

Anyone know what the correct way to do this is?

			regards, tom lane

Wed, 23 Jan 2002 18:16:12 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Checking for undefined in Perl interface code?
man perlguts:
        If you want to know if this variable (or any other SV) is
        actually defined, you can call:

            SvOK(SV*)

        The scalar undef value is stored in an SV instance called
        PL_sv_undef.  Its address can be used whenever an SV* is
        needed.

May be:
if (! (SvOK(perlret) && perlret != &PL_sv_undef) ) {...


Tom Lane wrote:

> PL/Perl tries to handle an "undef" result from a Perl function (which
> should convert to a SQL NULL) with code like so:
> 
>     /* XXX is this the approved way to check for an undef result? */
>     if (perlret == &PL_sv_undef)
>     {
>         retval = (Datum) 0;
>         fcinfo->isnull = true;
>     }
>     else
>     {
> 	// handle non-null result
>     }
> 
> But I find that it doesn't work, at least not on RH Linux 7.2 with
> perl 5.6.0.  The if-test fails to notice undef results.
> 
> Anyone know what the correct way to do this is?
> 
> 			regards, tom lane
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 
> 


-- 
Teodor Sigaev
teodor@stack.net



Thu, 24 Jan 2002 12:25:48 +0300
Teodor Sigaev <teodor@stack.net>
Re: Checking for undefined in Perl interface code?
Teodor Sigaev <teodor@stack.net> writes:
> May be:
> if (! (SvOK(perlret) && perlret != &PL_sv_undef) ) {...

Apparently the correct way is

	if (! (perlret && SvOK(perlret))) ...

Thanks for the tip.

			regards, tom lane

Thu, 24 Jan 2002 11:54:56 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: Checking for undefined in Perl interface code? 