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

pgsql: PL/Python: Accept strings in functions returning compositetypes

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: PL/Python: Accept strings in functions returning compositetypes
Date: 2012-04-26 18:12:34
Message-ID: E1SNTBC-00071z-VR@gemulon.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-committers
PL/Python: Accept strings in functions returning composite types

Before 9.1, PL/Python functions returning composite types could return
a string and it would be parsed using record_in.  The 9.1 changes made
PL/Python only expect dictionaries, tuples, or objects supporting
getattr as output of composite functions, resulting in a regression
and a confusing error message, as the strings were interpreted as
sequences and the code for transforming lists to database tuples was
used.  Fix this by treating strings separately as before, before
checking for the other types.

The reason why it's important to support string to database tuple
conversion is that trigger functions on tables with composite columns
get the composite row passed in as a string (from record_out).
Without supporting converting this back using record_in, this makes it
impossible to implement pass-through behavior for these columns, as
PL/Python no longer accepts strings for composite values.

A better solution would be to fix the code that transforms composite
inputs into Python objects to produce dictionaries that would then be
correctly interpreted by the Python->PostgreSQL counterpart code.  But
that would be too invasive to backpatch to 9.1, and it is too late in
the 9.2 cycle to attempt it.  It should be revisited in the future,
though.

Reported as bug #6559 by Kirill Simonov.

Jan UrbaƄski

Branch
------
REL9_1_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/4fa520f147992616a08e5dbb34620dc46d664fc2

Modified Files
--------------
src/pl/plpython/expected/plpython_record.out  |   16 ++++
src/pl/plpython/expected/plpython_trigger.out |   37 ++++++++++
src/pl/plpython/plpython.c                    |   94 +++++++++++++------------
src/pl/plpython/sql/plpython_record.sql       |   10 +++
src/pl/plpython/sql/plpython_trigger.sql      |   36 ++++++++++
5 files changed, 149 insertions(+), 44 deletions(-)

pgsql-committers by date

Next:From: Tom LaneDate: 2012-04-26 18:18:07
Subject: pgsql: Fix oversight in recent parameterized-path patch.
Previous:From: Peter EisentrautDate: 2012-04-26 17:09:38
Subject: pgsql: psql: Tab completion updates

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