The way to reproduce:

CREATE OR REPLACE FUNCTION foobar(a integer[])
RETURNS SETOF int8 AS
$$
    def getplan(name, query, args):
        if SD.has_key(name):
            plpy.warning("Using cached plan %s" % name)
            return SD[name]

        plpy.warning("Prepare plan %s" % name);
        plan = plpy.prepare(query, args)
        plpy.warning("Plan %s prepared" % name);
        SD[name] = plan
        return plan

    for s in a:
        userPlan = getplan('fooplan', 'select 1', []);
        rrr =  plpy.execute(plan, [])  # variable plan isn't defined!
        ret = s
        yield ret
$$
LANGUAGE 'plpythonu';

On 9.0beta2 (instead of correct message "<type 'exceptions.NameError'>: global name 'plan' is not defined"):
postgres=#  select foobar('{1,2,3}');
WARNING:  Prepare plan fooplan
CONTEXT:  PL/Python function "foobar"
WARNING:  PL/Python: plpy.SPIError: unrecognized error in PLy_spi_prepare
CONTEXT:  PL/Python function "foobar"
ERROR:  error fetching next item from iterator
CONTEXT:  PL/Python function "foobar"
postgres=#  select foobar('{1,2,3}');
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
!?>

Log:
TRAP: FailedAssertion("!(edata->elevel == 20)", File: "elog.c", Line: 1280)

8.4.4 haves essentially the same bug.

--
Teodor Sigaev                                   E-mail: teo...@sigaev.ru
                                                   WWW: http://www.sigaev.ru/

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to