Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4128211

Browse files
committed
Skip dropped attributes when converting Python objects to tuples
Pay attention to the attisdropped field and skip over TupleDesc fieldsthat have it set. Not a real problem until we get table returningfunctions, but it's the right thing to do anyway.Jan Urbański
1 parent59ea9ef commit4128211

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

‎src/pl/plpython/plpython.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,6 +2304,9 @@ PLyMapping_ToTuple(PLyTypeInfo *info, PyObject *mapping)
23042304
PyObject*volatilevalue;
23052305
PLyObToDatum*att;
23062306

2307+
if (desc->attrs[i]->attisdropped)
2308+
continue;
2309+
23072310
key=NameStr(desc->attrs[i]->attname);
23082311
value=NULL;
23092312
att=&info->out.r.atts[i];
@@ -2354,6 +2357,7 @@ PLySequence_ToTuple(PLyTypeInfo *info, PyObject *sequence)
23542357
HeapTupletuple;
23552358
Datum*values;
23562359
bool*nulls;
2360+
volatileintidx;
23572361
volatileinti;
23582362

23592363
Assert(PySequence_Check(sequence));
@@ -2364,7 +2368,13 @@ PLySequence_ToTuple(PLyTypeInfo *info, PyObject *sequence)
23642368
* plpython developer's errors we are strict here
23652369
*/
23662370
desc=lookup_rowtype_tupdesc(info->out.d.typoid,-1);
2367-
if (PySequence_Length(sequence)!=desc->natts)
2371+
idx=0;
2372+
for (i=0;i<desc->natts;i++)
2373+
{
2374+
if (!desc->attrs[i]->attisdropped)
2375+
idx++;
2376+
}
2377+
if (PySequence_Length(sequence)!=idx)
23682378
ereport(ERROR,
23692379
(errcode(ERRCODE_DATATYPE_MISMATCH),
23702380
errmsg("length of returned sequence did not match number of columns in row")));
@@ -2376,16 +2386,20 @@ PLySequence_ToTuple(PLyTypeInfo *info, PyObject *sequence)
23762386
/* Build tuple */
23772387
values=palloc(sizeof(Datum)*desc->natts);
23782388
nulls=palloc(sizeof(bool)*desc->natts);
2389+
idx=0;
23792390
for (i=0;i<desc->natts;++i)
23802391
{
23812392
PyObject*volatilevalue;
23822393
PLyObToDatum*att;
23832394

2395+
if (desc->attrs[i]->attisdropped)
2396+
continue;
2397+
23842398
value=NULL;
23852399
att=&info->out.r.atts[i];
23862400
PG_TRY();
23872401
{
2388-
value=PySequence_GetItem(sequence,i);
2402+
value=PySequence_GetItem(sequence,idx);
23892403
Assert(value);
23902404
if (value==Py_None)
23912405
{
@@ -2407,6 +2421,8 @@ PLySequence_ToTuple(PLyTypeInfo *info, PyObject *sequence)
24072421
PG_RE_THROW();
24082422
}
24092423
PG_END_TRY();
2424+
2425+
idx++;
24102426
}
24112427

24122428
tuple=heap_form_tuple(desc,values,nulls);
@@ -2441,6 +2457,9 @@ PLyObject_ToTuple(PLyTypeInfo *info, PyObject *object)
24412457
PyObject*volatilevalue;
24422458
PLyObToDatum*att;
24432459

2460+
if (desc->attrs[i]->attisdropped)
2461+
continue;
2462+
24442463
key=NameStr(desc->attrs[i]->attname);
24452464
value=NULL;
24462465
att=&info->out.r.atts[i];

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp