Re: TODO request: multi-dimensional arrays in PL/pythonU - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: TODO request: multi-dimensional arrays in PL/pythonU
Date
Msg-id 1376526855.11756.5.camel@vanquo.pezone.net
Whole thread Raw
In response to TODO request: multi-dimensional arrays in PL/pythonU  (Josh Berkus <josh@agliodbs.com>)
Responses Re: TODO request: multi-dimensional arrays in PL/pythonU  (Claudio Freire <klaussfreire@gmail.com>)
List pgsql-hackers
On Tue, 2013-08-13 at 14:30 -0700, Josh Berkus wrote:
> Currently PL/python has 1 dimension hardcoded for returning arrays:
> 
> create or replace function nparr ()
> returns float[][]
> language plpythonu
> as $f$
> from numpy import array
> x = ((1.0,2.0),(3.0,4.0),(5.0,6.0),)
> return x
> $f$;

There is no way to know how many dimensions the function expects to get
back.  (float[][] doesn't actually mean anything.)  So when converting
the return value back to SQL, you'd have to guess, is the first element
convertible to float (how do you know?), if not, does it support the
sequence protocol, if yes, so let's try to construct a multidimensional
array.  What if the first element is a float but the second is not?

It would be useful to have a solution for that, but it would need to be
more principled than what I just wrote.





pgsql-hackers by date:

Previous
From: Josh Berkus
Date:
Subject: Re: danger of stats_temp_directory = /dev/shm
Next
From: Tom Lane
Date:
Subject: Re: danger of stats_temp_directory = /dev/shm