On Sat, Mar 3, 2012 at 12:19, <marko@kobaz.net> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 6511
> Logged by: Mark Murawski
> Email address: marko@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!