Re: strange bug in plperl - Mailing list pgsql-hackers

From Darko Prenosil
Subject Re: strange bug in plperl
Date
Msg-id 200407051630.27350.darko.prenosil@finteh.hr
Whole thread Raw
In response to strange bug in plperl  (Andrew Dunstan <andrew@dunslane.net>)
Responses Re: strange bug in plperl  (Andrew Dunstan <andrew@dunslane.net>)
List 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


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Bug in PL/Perl CVS head w/spi patch
Next
From: Andrew Dunstan
Date:
Subject: Re: strange bug in plperl