Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 0F8AF8E352A for ; Sat, 3 Mar 2012 15:20:07 -0400 (AST) Received: from mahout.postgresql.org ([98.129.198.123]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S3uUt-00005K-2T for pgsql-bugs@postgresql.org; Sat, 03 Mar 2012 19:20:05 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S3uUf-0007sW-7h for pgsql-bugs@postgresql.org; Sat, 03 Mar 2012 19:19:50 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1S3uUe-0005ER-RD for pgsql-bugs@postgresql.org; Sat, 03 Mar 2012 19:19:48 +0000 Date: Sat, 03 Mar 2012 19:19:48 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD To: pgsql-bugs@postgresql.org From: marko@kobaz.net X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201203/24 X-Sequence-Number: 32585 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 table mytable ( id integer ); -- CREATE OR REPLACE FUNCTION mytrigger() RETURNS trigger AS $BODY$ return undef $BODY$ LANGUAGE plperlu VOLATILE COST 100; -- CREATE TRIGGER "insert" BEFORE INSERT ON mytable FOR EACH ROW EXECUTE PROCEDURE mytrigger(); -- 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=3D# select * from myfunc(); ERROR: couldn't fetch $_TD at line 4. CONTEXT: PL/Perl function "myfunc" -- this works: CREATE OR REPLACE FUNCTION myfunc() RETURNS text AS $BODY$ package foo; sub foo { package main; spi_exec_query(q{INSERT INTO mytable VALUES (1) RETURNING id}); }; package main; foo::foo(); return; $BODY$ LANGUAGE plperlu VOLATILE COST 100; select * from myfunc(); myfunc -------- (1 row) drop table mytable; drop function mytrigger(); drop function myfunc();