@@ -2304,6 +2304,9 @@ PLyMapping_ToTuple(PLyTypeInfo *info, PyObject *mapping)
2304
2304
PyObject * volatile value ;
2305
2305
PLyObToDatum * att ;
2306
2306
2307
+ if (desc -> attrs [i ]-> attisdropped )
2308
+ continue ;
2309
+
2307
2310
key = NameStr (desc -> attrs [i ]-> attname );
2308
2311
value = NULL ;
2309
2312
att = & info -> out .r .atts [i ];
@@ -2354,6 +2357,7 @@ PLySequence_ToTuple(PLyTypeInfo *info, PyObject *sequence)
2354
2357
HeapTuple tuple ;
2355
2358
Datum * values ;
2356
2359
bool * nulls ;
2360
+ volatile int idx ;
2357
2361
volatile int i ;
2358
2362
2359
2363
Assert (PySequence_Check (sequence ));
@@ -2364,7 +2368,13 @@ PLySequence_ToTuple(PLyTypeInfo *info, PyObject *sequence)
2364
2368
* plpython developer's errors we are strict here
2365
2369
*/
2366
2370
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 )
2368
2378
ereport (ERROR ,
2369
2379
(errcode (ERRCODE_DATATYPE_MISMATCH ),
2370
2380
errmsg ("length of returned sequence did not match number of columns in row" )));
@@ -2376,16 +2386,20 @@ PLySequence_ToTuple(PLyTypeInfo *info, PyObject *sequence)
2376
2386
/* Build tuple */
2377
2387
values = palloc (sizeof (Datum ) * desc -> natts );
2378
2388
nulls = palloc (sizeof (bool ) * desc -> natts );
2389
+ idx = 0 ;
2379
2390
for (i = 0 ; i < desc -> natts ; ++ i )
2380
2391
{
2381
2392
PyObject * volatile value ;
2382
2393
PLyObToDatum * att ;
2383
2394
2395
+ if (desc -> attrs [i ]-> attisdropped )
2396
+ continue ;
2397
+
2384
2398
value = NULL ;
2385
2399
att = & info -> out .r .atts [i ];
2386
2400
PG_TRY ();
2387
2401
{
2388
- value = PySequence_GetItem (sequence , i );
2402
+ value = PySequence_GetItem (sequence , idx );
2389
2403
Assert (value );
2390
2404
if (value == Py_None )
2391
2405
{
@@ -2407,6 +2421,8 @@ PLySequence_ToTuple(PLyTypeInfo *info, PyObject *sequence)
2407
2421
PG_RE_THROW ();
2408
2422
}
2409
2423
PG_END_TRY ();
2424
+
2425
+ idx ++ ;
2410
2426
}
2411
2427
2412
2428
tuple = heap_form_tuple (desc , values , nulls );
@@ -2441,6 +2457,9 @@ PLyObject_ToTuple(PLyTypeInfo *info, PyObject *object)
2441
2457
PyObject * volatile value ;
2442
2458
PLyObToDatum * att ;
2443
2459
2460
+ if (desc -> attrs [i ]-> attisdropped )
2461
+ continue ;
2462
+
2444
2463
key = NameStr (desc -> attrs [i ]-> attname );
2445
2464
value = NULL ;
2446
2465
att = & info -> out .r .atts [i ];
0 commit comments