Skip site navigation (1) Skip section navigation (2)

Re: PL/Python array support

From: Joshua Tolley <eggyknap(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Teodor Sigaev <teodor(at)sigaev(dot)ru>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: PL/Python array support
Date: 2009-12-02 03:53:49
Message-ID: 20091202035349.GA20931@eddie (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
On Fri, Nov 20, 2009 at 12:00:24AM +0200, Peter Eisentraut wrote:
> On fre, 2009-11-13 at 18:46 +0300, Teodor Sigaev wrote:
> > 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"
> Fixed with additional error check and regression test.  (The problem
> could be more simply demonstrated by returning any non-sequence from the
> function.)  Thanks for catching it.

I've finally gotten around to getting a review done, and basically it looks
good to me. There appears to be a problem with the tests in that the expected
output doesn't include the test_type_conversion_array_error() function
mentioned in sql/plpython_types.sql. Diff generated by the regression test is
attached. Other than that problem, though, the code looks fine to me (should I
presume to judge Peter's code? :). Aside from the problem mentioned above, the
tests work fine, and seem fairly comprehensive. Other testing I've done also

This patch doesn't include any documentation; my reading of the PL/Python docs
suggests that's probably acceptable, as the existing docs don't talk about its
array handling. That said, it might be useful to include an example, to show
for instance that identical PL/Python code could create either an array of a
type or a set of rows of that type:

5432 josh(at)josh*# create function return_set() returns setof int as $$ return
(1, 2, 3, 4, 5) $$ language plpythonu;
5432 josh(at)josh*# create function return_arr() returns int[] as $$ return (1,
2, 3, 4, 5) $$ language plpythonu;
5432 josh(at)josh*# select return_arr();
(1 row)

5432 josh(at)josh*# select * from return_set();
(5 rows)

Perhaps that's overkill, though.

Joshua Tolley / eggyknap
End Point Corporation

In response to


pgsql-hackers by date

Next:From: Robert HaasDate: 2009-12-02 04:04:34
Subject: Re: Page-level version upgrade (was: Block-level CRC checks)
Previous:From: Robert HaasDate: 2009-12-02 03:52:32
Subject: Re: [PATCH] bugfix for int2vectorin

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group