plpythonu array parameter

From: Sim Zacks <sim(at)compulab(dot)co(dot)il>
To: pgsql-general(at)postgresql(dot)org
Subject: plpythonu array parameter
Date: 2006-12-06 09:22:29
Message-ID: el6267$14j6$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I ran into an interesting issue trying to pass an array to a plpythonu function (Postgresql 8.03).
When I googled the issue I found a number of people asking similar questions and they haven't found
an answer. The problem is that there is no type mapped from a postgresql array to a python list.

These conversion functions will map between a postgresql array and a python list and back. Is there
a way to stick this in the integration code somewhere, so that every time an array is passed to/from
a python function it converts it transparently?

In the python function itself this type of code will work, what I don't know is how to change the
internals so that when an array variable is passed in it automatically puts it through this code and
hands off a python list variable.

The second function would work as is, and return a postgresql array.

Of course both would have to work with any type of array and not just text[]

create or replace function pgarray_to_pylist(text[]) returns {python list} as
$$
parm=args[0]
parm=parm.replace("{","[").replace("}","]")
pylist=eval(parm)
return pylist
$$ language 'plpythonu'

create or replace function pylist_to_pgarray({python list}) return text[] as
$$
parm=`args[0]`
parm=parm.replace("[","{").replace("]","}")
return parm
$$ language 'plpythonu'

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Devrim GUNDUZ 2006-12-06 09:26:02 Re: Error in installing compat-postgresql-libs rpm
Previous Message Albe Laurenz 2006-12-06 09:01:32 Re: Errors trying to install compat-postgresql-libs: