From: | "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com> |
---|---|
To: | Peter Fein <pfein(at)pobox(dot)com> |
Cc: | Postgresql-General list <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Return SETOF or array from pl/python |
Date: | 2005-07-15 16:33:58 |
Message-ID: | 42D7E576.9050001@commandprompt.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Peter Fein wrote:
> Is it possible to return a SETOF text or a text[] from pl/python?
>
> I've got the following test cases:
>
> CREATE OR REPLACE FUNCTION arf()
> RETURNS text[] LANGUAGE plpythonu AS
> $$return ["one", "two", "three"]$$;
>
> SELECT arf();
>
> ERROR: missing dimension value
>
> CREATE OR REPLACE FUNCTION arf2()
> RETURNS text[] LANGUAGE plpythonu AS
> $$return '{"one", "two", "three"}'$$;
>
> SELECT arf2();
>
> arf2
> -----------------
> {one,two,three}
> (1 row)
>
> CREATE OR REPLACE FUNCTION srf()
> RETURNS SETOF text LANGUAGE plpythonu AS
> $$return ["one", "two", "three"]$$;
>
> SELECT * FROM srf();
>
> srf
> -------------------------
> ['one', 'two', 'three']
> (1 row)
>
> SELECT srf();
> Never returns.
I am not an everyday python programmer but I am pretty sure that you are
trying to return a list in arf(). You can't return a list you have to
return the array type which is why arf2 works.
The reasons srf works is because you are just returning text in general
regardless that it is formatting to a list.
Sincerely,
Joshua D. Drake
>
> I can obviously use something like arf2 (manually stringifying w/i
> python) but this seems ugly. I'd really prefer to return a set, rather
> than an array.
>
--
Your PostgreSQL solutions company - Command Prompt, Inc. 1.800.492.2240
PostgreSQL Replication, Consulting, Custom Programming, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, plPerlNG - http://www.commandprompt.com/
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Fein | 2005-07-15 16:49:49 | Re: Return SETOF or array from pl/python |
Previous Message | Alvaro Herrera | 2005-07-15 16:27:42 | Re: CVS - psql segfault |