Re: Array of composite types returned from python

From: "Behn, Edward (EBEHN)" <EBEHN(at)arinc(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Array of composite types returned from python
Date: 2014-03-31 18:43:51
Message-ID: 93F16B4BD93A7840AC75EB16E9494C7B1537EB39@EXANPMB2.arinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Attached is the patch for the code change described below:

Project Name : Allow return array of composites from PL/Python

Currently, a SQL array of non-composite variables can be returned from
PL/Python code by returning a iterable object. A SQL composite value may be
returned by returning a iterable or a subscriptable object. However,
returning a list of objects that each represent a composite variable is not
converted to an SQL array of composite variables. This code change allows
that conversion to take place. This allows for smooth, elegant interface
between SQL and PL/Python.

This is a patch against MASTER

The patch compiles successfully. All the standard regression tests pass.
Some modifications are needed for the .out files in order for the PL/Python
regression tests to pass. This is due to the fact that the current .out
files expect errors when a python array of composite is converted, where my
modifications expect success. All tests have been performed with both
Python2 and Python3.

-Ed

From: pgsql-hackers-owner(at)postgresql(dot)org
[mailto:pgsql-hackers-owner(at)postgresql(dot)org] On Behalf Of Behn, Edward
(EBEHN)
Sent: Thursday, March 20, 2014 5:54 PM
To: pgsql-hackers(at)postgresql(dot)org
Subject: [HACKERS] Array of composite types returned from python

I've endeavored to enable the return of arrays of composite types from code
written in PL/Python. It seems that this can be accomplished though a very
minor change to the code:

On line 401 in the file src/pl/plpython/plpy_typeio.c, remove the error
report "PL/Python functions cannot return type." and replace it with the
command

arg->func = PLyObject_ToComposite;

From all that I can see, this does exactly what I want. A python list of
tuples is converted to an array of composite types in SQL.

I ran the main and python regression suites for both python2 and python3
with assert enabled. The only discrepancies I got were ones that were due to
the output expecting an error. When I altered the .out files to the expected
behavior, it matched just fine.

Am I missing anything, (ie memory leak, undesirable behavior elsewhere)?

-Ed

Ed Behn / Staff Engineer / Airline and Network Services
Information Management Services
2551 Riva Road, Annapolis, MD 21401 USA
Phone: 410.266.4426 / Cell: 240.696.7443
ebehn(at)arinc(dot)com
<http://www.rockwellcollins.com/> www.rockwellcollins.com

Attachment Content-Type Size
PLPythonCompositeArrays_v1.patch application/octet-stream 4.1 KB
smime.p7s application/pkcs7-signature 5.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2014-03-31 18:44:45 Re: Still something fishy in the fastpath lock stuff
Previous Message Tom Lane 2014-03-31 18:43:38 Re: About adding an attribute to a system catalog