Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: Function returning SETOF using plpythonu


  • From: Marcin Stępnicki <mstepnicki(at)gmail(dot)com>
  • To: pgsql-sql(at)postgresql(dot)org
  • Subject: Re: Function returning SETOF using plpythonu
  • Date: Fri, 26 Jan 2007 23:17:58 +0100
  • Message-id: <pan(dot)2007(dot)01(dot)26(dot)22(dot)17(dot)58(dot)397717(at)gmail(dot)com>

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(at)jabber(dot)org *---' http://www.naszedzieci.org 





Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group