Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 81C1D9FB2A6 for ; Fri, 26 Jan 2007 18:18:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 08934-01 for ; Fri, 26 Jan 2007 18:18:24 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id 2B3DD9FB1A5 for ; Fri, 26 Jan 2007 18:18:28 -0400 (AST) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1HAZOi-0005P1-RE for pgsql-sql@postgresql.org; Fri, 26 Jan 2007 23:18:16 +0100 Received: from 85-219-158-6.matarnia.pl ([85.219.158.6]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 26 Jan 2007 23:18:16 +0100 Received: from mstepnicki by 85-219-158-6.matarnia.pl with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 26 Jan 2007 23:18:16 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: =?iso-8859-2?q?Marcin_St=EApnicki?= Subject: Re: Function returning SETOF using plpythonu Date: Fri, 26 Jan 2007 23:17:58 +0100 Organization: Linux.PL Lines: 31 Message-ID: References: <45BA3964.8070704@ualg.pt> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 85-219-158-6.matarnia.pl User-Agent: Pan/0.14.2.91 (As She Crawled Across the Table (Debian GNU/Linux)) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.721 tagged_above=0 required=5 tests=AWL, BAYES_05, INFO_TLD, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200701/144 X-Sequence-Number: 27296 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: > 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