Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > Re: how to retu...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 3396 of 3799
Post > Topic >>

Re: how to returns set of records in PL/python

by gherzig@[EMAIL PROTECTED] (Gerardo Herzig) Apr 7, 2008 at 10:03 AM

Anoop G wrote:

>Hi ,
>
>  Iam new to plpython,how can I return a  recordset from a plpython
>function?
>
>  Is there is any way give me an example;
>
>
>plpgsql function
>--------------------------------
>
>CREATE OR REPLACE FUNCTION function_to_get_all_countries() RETURNS SETOF
>RECORD AS $BODY$
>DECLARE
>
>    r RECORD;
>
>BEGIN
>
>    FOR r IN SELECT  pk_bint_country_id,vchr_country FROM tbl_country
LOOP
>        RETURN NEXT r;
>        END LOOP;
>    RETURN;
>
>END
>$BODY$ LANGUAGE 'plpgsql';
>
>
>
>
>How i can get the same result using plpythonu and how I can call the
>function (is there any user defined type required like in plpgsql)?
>
>Thanks in advance
>
>Anoop
>
>  
>
Yes, plpython can return setofs. You may need to define a new type for
that.
After that you can return a list, tuple, dictionary, set, generator 
object, or any

You may also check the plpython version, as i recall, its kind of *new* 
issue.

This works on 8.2.5, python 2.5,

For a simple case, something like that would work
regression=# \d countries
           Table "public.countries"
    Column    |       Type        | Modifiers
--------------+-------------------+-----------
 country_id   | integer           |
 country_name | character varying |


CREATE OR REPLACE FUNCTION get_countries()
returns setof countries
security definer
as
$$
return plpy.execute("select * from countries")

$$ language plpythonu;

Hope that helps.
Gerardo


-- 
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 3 Posts in Topic:
how to returns set of records in PL/python
anoopmadavoor@[EMAIL PROT  2008-04-07 18:17:22 
Re: how to returns set of records in PL/python
gherzig@[EMAIL PROTECTED]  2008-04-07 10:03:38 
Re: how to returns set of records in PL/python
gherzig@[EMAIL PROTECTED]  2008-04-07 10:04:31 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 21:34:54 CST 2008.