Bug in plpython's Python Generators

From: Jean-Baptiste Quenot <jbq(at)caraldi(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Bug in plpython's Python Generators
Date: 2010-10-21 12:20:16
Message-ID: AANLkTimLMr-u89f7vf4AckB6xH=V3uf+PxraOg4XB4=o@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi there,

I can't make Python Generators to work reliably. According to the
documentation, this should work:

CREATE OR REPLACE FUNCTION foobar()
RETURNS SETOF text AS
$$
for s in ('Hello', 'World'):
plpy.execute('select 1')
yield s
$$
LANGUAGE 'plpythonu';

I get this error when calling the function:

test=# select foobar();
ERROR: error fetching next item from iterator
CONTEXT: PL/Python function "foobar"

When I remove the dummy plpy.execute() call, it works:

CREATE OR REPLACE FUNCTION foobar()
RETURNS SETOF text AS
$$
for s in ('Hello', 'World'):
yield s
$$
LANGUAGE 'plpythonu';

test=# select foobar();
foobar
--------
Hello
World
(2 rows)

Seems like calls to plpy.execute() conflict with generators. This is
the case both on versions 8.4.4 and 9.0.1.

All the best,
--
Jean-Baptiste Quenot

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Marko Tiikkaja 2010-10-21 12:32:54 Re: Review: Fix snapshot taking inconsistencies
Previous Message Dimitri Fontaine 2010-10-21 09:49:41 Re: pg_hba.conf host name wildcard support