From: | Rajarshi Guha <rguha(at)indiana(dot)edu> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | passing an array type to a plpython procedure |
Date: | 2007-03-11 22:37:26 |
Message-ID: | 1173652646.4908.10.camel@panda |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi, I have a table in which a column is of type real[12]
I also have a function written in pl/Python that will accept two
arguments of type real[12].
However when I send in the values by doing:
select sim(ARRAY[1,1,1,1,1,1,1,1,1,1,1,1], ARRAY[1,1,1,1,1,1,1,1,1,1,1,1])
I get an error indicating that the input args are of type 'str' rather
than a list type as I would have expected. I found this posting
(http://www.thescripts.com/forum/thread399934.html) from 2005, which
indicates that a pl/Python procedure will not see an array type as array
but rather as a string.
Has this aspect been updated? My current code parses the string, to get
at the array elements (which is obviously prone to failure etc etc) and
I'm sure I could get a bit of a speed up if I could avoid this. My code
looks like:
create or replace function momsim3d(real[12], real[12]) returns real as
'
query = args[0]
target = args[1]
query = query[1:len(query)-1]
target = target[1:len(target)-1]
query = [float(x) for x in query.split(",")]
target = [float(x) for x in target.split(",")]
sum = 0.0
for i in range(0,12): sum += abs(query[i] - target[i])
return 1.0/(1.0+sum/12.0)
' language plpythonu;
Ubuntu 6.10
Postgresql 7.4
Thanks,
-------------------------------------------------------------------
Rajarshi Guha <rguha(at)indiana(dot)edu>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
All the evidence concerning the universe has not yet been collected,
so there's still hope.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2007-03-12 02:42:06 | Re: passing an array type to a plpython procedure |
Previous Message | Bill Moran | 2007-03-11 19:57:41 | Re: question about stored procedure / function |