Re: strange bug in plperl

From: Darko Prenosil <darko(dot)prenosil(at)finteh(dot)hr>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, plperlng-devel(at)pgfoundry(dot)org
Subject: Re: strange bug in plperl
Date: 2004-07-05 14:30:27
Message-ID: 200407051630.27350.darko.prenosil@finteh.hr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Because that is exactly count of "tstset" function being called. Set returning
functions are called recursively until SRF_RETURN_DONE is returned, and that
in You case means until last row is fetched.

When You programming functions in "C", there is SRF_ISFIRST_CALL function that
returns "true" if function is called for the first time, so You can write
something like this:

if (SRF_ISFIRST_CALL())
{
//Code that executes only once
}
else
{
//Code that executes per row
}

I do not know how this works with plperl, and this could be a bug, because
only "return [{i=>1,v=>"one"},{i=>2,v=>"two"}];" should be executed more than
once (that is the way it is working in pl/psql).
I'm sorry I can't help more, but do not know much about plperl :-(
Hope some plperl guru will know more...

Regards !

On Monday 05 July 2004 15:33, Andrew Dunstan wrote:
> Can anyone suggest why I might be seeing this effect (each notice comes
> out once per row plus once per function call)
>
> thanks
>
> andrew
>
> andrew=# create function tstset() returns setof tst language plperl as $$
> andrew$# elog(NOTICE,"tstset called");
> andrew$# return [{i=>1,v=>"one"},{i=>2,v=>"two"}];
> andrew$# $$;
> CREATE FUNCTION
> andrew=# select * from tstset();
> NOTICE: tstset called
> NOTICE: tstset called
> NOTICE: tstset called
> i | v
> ---+-----
> 1 | one
> 2 | two
> (2 rows)
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2004-07-05 15:37:04 Re: strange bug in plperl
Previous Message Andrew Dunstan 2004-07-05 13:52:23 Re: Bug in PL/Perl CVS head w/spi patch