Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD

From: Alex Hunsaker <badalex(at)gmail(dot)com>
To: marko(at)kobaz(dot)net
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD
Date: 2012-03-07 04:08:25
Message-ID: CAFaPBrQRwr7OevWjeFwU2+E34Vt+wfy1_GmhNm4=Yw0_dPLL_w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

Attachment Content-Type Size
plperl_nested_pkg_trigger.patch text/x-patch 419 bytes

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Phil Sorber 2012-03-07 06:49:35 Re: Extension tracking temp table and causing update failure
Previous Message Tom Lane 2012-03-07 00:49:28 Re: BUG #6480: NLS text width problem