Re: Function returning SETOF using plpythonu - Mailing list pgsql-sql

From Marcin Stępnicki
Subject Re: Function returning SETOF using plpythonu
Date
Msg-id pan.2007.01.26.22.17.58.397717@gmail.com
Whole thread Raw
In response to Function returning SETOF using plpythonu  (Luís Sousa <llsousa@ualg.pt>)
Responses Re: Function returning SETOF using plpythonu  (Luís Sousa <llsousa@ualg.pt>)
List pgsql-sql
Dnia Fri, 26 Jan 2007 17:24:52 +0000, Luís Sousa napisał(a):

> Hi,
> 
> Is it possible to return rows from a function written in plpythonu using 
> SETOF?
> 
> Example:
> CREATE FUNCTION "test_python_setof"()
> RETURNS SETOF text AS '
>     records=plpy.execute("SELECT name FROM interface");
>     return records
> ' LANGUAGE 'plpythonu';
> 
> With this code is returning the object from the execution:
> <PLyResult object at 0xb703e458>

plpy.execute returns dictionary, and you need a list. You may try this:

CREATE FUNCTION "test_python_setof"()
RETURNS SETOF text AS '   records=plpy.execute("SELECT name FROM interface");   return  [ (r["name"]) for r in
records]
' LANGUAGE 'plpythonu';

-- 
| And Do What You Will be the challenge | http://apcoln.linuxpl.org
|    So be it in love that harms none   | http://biznes.linux.pl
|   For this is the only commandment.   | http://www.juanperon.info
`---*  JID: Aragorn_Vime@jabber.org *---' http://www.naszedzieci.org 




pgsql-sql by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Intersection of two date interval
Next
From: Oisin Glynn
Date:
Subject: Re: [NOVICE] Windows 2K Installation difficulties...