Pay attention to the attisdropped field and skip over TupleDesc fields
that have it set. Not a real problem until we get table returning
functions, but it's the right thing to do anyway.
---
src/pl/plpython/plpython.c | 24 +++++++++++++++++++++---
1 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c
index 6de0365..9da7602 100644
--- a/src/pl/plpython/plpython.c
+++ b/src/pl/plpython/plpython.c
@@ -2286,6 +2286,9 @@ PLyMapping_ToTuple(PLyTypeInfo *info, PyObject *mapping)
PyObject *volatile value;
PLyObToDatum *att;

+ if (desc->attrs[i]->attisdropped)
+ continue;
+
key = NameStr(desc->attrs[i]->attname);
value = NULL;
att = &info->out.r.atts[i];
@@ -2336,17 +2339,23 @@ PLySequence_ToTuple(PLyTypeInfo *info, PyObject *sequence)
HeapTuple tuple;
Datum *values;
bool *nulls;
+ int idx;
volatile int i;

Assert(PySequence_Check(sequence));
-
/*
* Check that sequence length is exactly same as PG tuple's. We actually
* can ignore exceeding items or assume missing ones as null but to avoid
* plpython developer's errors we are strict here
*/
desc = lookup_rowtype_tupdesc(info->out.d.typoid, -1);
- if (PySequence_Length(sequence) != desc->natts)
+ idx = 0;
+ for (i = 0; i < desc->natts; ++i)
+ {
+ if (!desc->attrs[i]->attisdropped)
+ idx++;
+ }
+ if (PySequence_Length(sequence) != idx)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("length of returned sequence did not match number of columns in row")));
@@ -2358,16 +2367,20 @@ PLySequence_ToTuple(PLyTypeInfo *info, PyObject *sequence)
/* Build tuple */
values = palloc(sizeof(Datum) * desc->natts);
nulls = palloc(sizeof(bool) * desc->natts);
+ idx = 0;
for (i = 0; i < desc->natts; ++i)
{
PyObject *volatile value;
PLyObToDatum *att;

+ if (desc->attrs[i]->attisdropped)
+ continue;
+
value = NULL;
att = &info->out.r.atts[i];
PG_TRY();
{
- value = PySequence_GetItem(sequence, i);
+ value = PySequence_GetItem(sequence, idx);
Assert(value);
if (value == Py_None)
{
@@ -2389,6 +2402,8 @@ PLySequence_ToTuple(PLyTypeInfo *info, PyObject *sequence)
PG_RE_THROW();
}
PG_END_TRY();
+
+ idx++;
}

tuple = heap_form_tuple(desc, values, nulls);
@@ -2423,6 +2438,9 @@ PLyObject_ToTuple(PLyTypeInfo *info, PyObject *object)
PyObject *volatile value;
PLyObToDatum *att;

+ if (desc->attrs[i]->attisdropped)
+ continue;
+
key = NameStr(desc->attrs[i]->attname);
value = NULL;
att = &info->out.r.atts[i];
--
1.7.2.3


--------------060701080700030209080905
Content-Type: text/x-patch;
name="0011-Use-PyObject_New-instead-of-PyObject_NEW.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="0011-Use-PyObject_New-instead-of-PyObject_NEW.patch"

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-hackers @
categoriespostgresql
postedJan 2, '11 at 10:36a
activeJan 2, '11 at 10:36a
posts1
users1
websitepostgresql.org...
irc#postgresql

1 user in discussion

Jan Urbański: 1 post

People

Translate

site design / logo © 2022 Grokbase