plperl: Undefined subroutine &main::mksafefunc - Mailing list pgsql-bugs

From Michael Fuhr
Subject plperl: Undefined subroutine &main::mksafefunc
Date
Msg-id 20041121074741.GA66301@winnie.fuhr.org
Whole thread Raw
Responses Re: plperl: Undefined subroutine &main::mksafefunc
List pgsql-bugs
I've found another plperl bug in the most recent CVS sources (see
end of message for file versions).  Sorry if this is a known issue
but I don't remember seeing it.

If spi_exec_query() fails in a plperl function, subsequent calls
to plperl or plperlu functions that hadn't been previously loaded
will fail with "Undefined subroutine &main::mksafefunc".  Functions
that had already been loaded will continue to work, at least in
simple cases.  I don't know what conditions besides spi_exec_query()
failure will cause this problem, but syntax errors in the Perl code
itself don't appear to cause it.

In the examples below, if test2() is plperl then the subsequent
call to test3() will fail whether test3() is plperl or plperlu.
However, if test2() is plperlu then test3() will work either way.

The order of the CREATE FUNCTION statements is irrelevant; the call
order determines the failures.


\set VERBOSITY verbose

CREATE OR REPLACE FUNCTION test1() RETURNS INTEGER AS $$
return 1;
$$ LANGUAGE plperl;

CREATE OR REPLACE FUNCTION test2() RETURNS INTEGER AS $$
spi_exec_query("SELECT FOOBAR");  # intentional error
return 2;
$$ LANGUAGE plperl;

CREATE OR REPLACE FUNCTION test3() RETURNS INTEGER AS $$
return 3;
$$ LANGUAGE plperl;

SELECT test1();
 test1
-------
     1
(1 row)

SELECT test2();
ERROR:  42703: column "foobar" does not exist
CONTEXT:  SQL statement "SELECT FOOBAR"
LOCATION:  transformColumnRef, parse_expr.c:1085

SELECT test3();
ERROR:  XX000: creation of function failed:     (in cleanup) Undefined subroutine &main::mksafefunc called at (eval 6)
line2. 
LOCATION:  plperl_create_sub, plperl.c:709

SELECT test1();
 test1
-------
     1
(1 row)


File versions:

/ppport.h/1.8/Mon Aug 30 02:54:41 2004//
/spi_internal.c/1.5/Mon Sep 13 20:08:59 2004//
/spi_internal.h/1.4/Mon Sep 13 20:08:59 2004//
/GNUmakefile/1.18/Sat Nov 20 20:53:13 2004//
/SPI.xs/1.10/Sat Nov 20 20:53:13 2004//
/plperl.c/1.59/Sat Nov 20 20:53:13 2004//

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-bugs by date:

Previous
From: John Hansen
Date:
Subject: Re: [HACKERS] split_part bug
Next
From: Tom Lane
Date:
Subject: Re: plperl: Undefined subroutine &main::mksafefunc