On Sat, Mar 3, 2012 at 12:19,  <ma...@kobaz.net> wrote:
> The following bug has been logged on the website:
>
> Bug reference:      6511
> Logged by:          Mark Murawski
> Email address:      ma...@kobaz.net
> PostgreSQL version: 9.1.3
> Operating system:   Linux - Debian Squeeze postgres 9.1 from backports
> Description:
>
> CREATE OR REPLACE FUNCTION myfunc()  RETURNS text AS $BODY$
> package foo;
> sub foo {
>  main::spi_exec_query(q{INSERT INTO mytable VALUES (1) RETURNING id});
> };
>
> package main;
> foo::foo();
> return;
> $BODY$  LANGUAGE plperlu VOLATILE  COST 100;
>
> --
>
> pbx=# select * from myfunc();
> ERROR:  couldn't fetch $_TD at line 4.
> CONTEXT:  PL/Perl function "myfunc"

[ Calling a plperl trigger function from a plperl function ]

Yeah, there were some optimization done for 9.1 to try and make calls
a bit faster. The problem is we are fetching "_TD" not "main::_TD",
which means we try to find and use $_TD from whatever the current
package is. This should only happen from a nested plperl to plperl
trigger where the outer call was in a different package, otherwise the
package is always main.

The attached fixes it for me, It would be great if you could confirm that.

Thanks for the report!
*** a/src/pl/plperl/plperl.c
--- b/src/pl/plperl/plperl.c
***************
*** 2062,2068 **** plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo,
  	ENTER;
  	SAVETMPS;
  
! 	TDsv = get_sv("_TD", 0);
  	if (!TDsv)
  		elog(ERROR, "couldn't fetch $_TD");
  
--- 2062,2068 ----
  	ENTER;
  	SAVETMPS;
  
! 	TDsv = get_sv("main::_TD", 0);
  	if (!TDsv)
  		elog(ERROR, "couldn't fetch $_TD");
  
-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply via email to