Re: PL/Python array support

Teodor Sigaev <teodor@sigaev.ru>

From: Teodor Sigaev <teodor@sigaev.ru>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-hackers@postgresql.org
Date: 2009-11-13T15:46:42Z
Lists: pgsql-hackers
CREATE OR REPLACE FUNCTION incr(stuff int[]) RETURNS int[] AS $$
for x in stuff:
     yield x+1
$$
LANGUAGE 'plpythonu';

# select incr(ARRAY[1,2,3]);
ERROR:  invalid memory alloc request size 18446744073709551608
CONTEXT:  while creating return value
PL/Python function "incr"


Suppose, it could be fixed by additional check in PLy_function_handler near line 
947 :
if (proc->is_setof) {
  ...
}
else if (PyIter_Check(plrv))
{
     ereport(ERROR,
            (errcode(ERRCODE_DATATYPE_MISMATCH),
             errmsg("returned object should be iterated"),
             errdetail("PL/Python returns iterable object in non-setof returning 
context")));
}


Peter Eisentraut wrote:
> On ons, 2009-11-04 at 16:02 +0200, Peter Eisentraut wrote:
>> Here is a patch to support arrays in PL/Python as parameters and
>> return values.
> 
> Slightly updated version with fixed reference counting.
> 
> 
> ------------------------------------------------------------------------
> 
> 

-- 
Teodor Sigaev                                   E-mail: teodor@sigaev.ru
                                                    WWW: http://www.sigaev.ru/