Search Postgresql Archives

passing an array type to a plpython procedure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>
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.




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux