@@ -180,9 +180,6 @@ static void CopySendInt32(CopyState cstate, int32 val);
180
180
static bool CopyGetInt32 (CopyState cstate , int32 * val );
181
181
static void CopySendInt16 (CopyState cstate , int16 val );
182
182
static bool CopyGetInt16 (CopyState cstate , int16 * val );
183
- static void InitForeignCopyFrom (EState * estate , ResultRelInfo * resultRelInfo ,
184
- CopyState cstate , char * dest_relname );
185
- static void EndForeignCopyFrom (EState * estate , ResultRelInfo * resultRelInfo );
186
183
187
184
188
185
/*
@@ -2314,7 +2311,6 @@ CopyFrom(CopyState cstate)
2314
2311
TupleTableSlot * partition_tuple_slot ;
2315
2312
int num_parted ,
2316
2313
num_partitions ;
2317
- int i ;
2318
2314
2319
2315
ExecSetupPartitionTupleRouting (cstate -> rel ,
2320
2316
1 ,
@@ -2351,16 +2347,15 @@ CopyFrom(CopyState cstate)
2351
2347
gettext_noop ("could not convert row type" ));
2352
2348
}
2353
2349
}
2354
-
2355
- /* If some partitions are foreign tables, init copy on remote end */
2356
- for (i = 0 ; i < num_partitions ; i ++ )
2357
- {
2358
- InitForeignCopyFrom (estate , partitions + i , cstate , NULL );
2359
- }
2360
2350
}
2361
2351
2362
2352
/* If we are copying to foreign table, init it */
2363
- InitForeignCopyFrom (estate , resultRelInfo , cstate , NULL );
2353
+ if (resultRelInfo -> ri_FdwRoutine &&
2354
+ FdwCopyFromIsSupported (resultRelInfo -> ri_FdwRoutine ))
2355
+ {
2356
+ resultRelInfo -> ri_FdwRoutine ->
2357
+ BeginForeignCopyFrom (estate , resultRelInfo , cstate , NULL );
2358
+ }
2364
2359
2365
2360
/*
2366
2361
* It's more efficient to prepare a bunch of tuples for insertion, and
@@ -2490,6 +2485,12 @@ CopyFrom(CopyState cstate)
2490
2485
saved_resultRelInfo = resultRelInfo ;
2491
2486
resultRelInfo = cstate -> partitions + leaf_part_index ;
2492
2487
2488
+ /* We do not yet have a way to insert into a foreign partition */
2489
+ if (resultRelInfo -> ri_FdwRoutine )
2490
+ ereport (ERROR ,
2491
+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
2492
+ errmsg ("cannot route inserted tuples to a foreign table" )));
2493
+
2493
2494
/*
2494
2495
* For ExecInsertIndexTuples() to work on the partition's indexes
2495
2496
*/
@@ -2710,7 +2711,12 @@ CopyFrom(CopyState cstate)
2710
2711
/*
2711
2712
* Shut down FDW.
2712
2713
*/
2713
- EndForeignCopyFrom (estate , resultRelInfo );
2714
+ if (resultRelInfo -> ri_FdwRoutine &&
2715
+ FdwCopyFromIsSupported (resultRelInfo -> ri_FdwRoutine ))
2716
+ {
2717
+ resultRelInfo -> ri_FdwRoutine -> EndForeignCopyFrom (
2718
+ estate , resultRelInfo );
2719
+ }
2714
2720
2715
2721
/* Close all the partitioned tables, leaf partitions, and their indices */
2716
2722
if (cstate -> partition_dispatch_info )
@@ -2734,8 +2740,6 @@ CopyFrom(CopyState cstate)
2734
2740
{
2735
2741
ResultRelInfo * resultRelInfo = cstate -> partitions + i ;
2736
2742
2737
- EndForeignCopyFrom (estate , resultRelInfo );
2738
-
2739
2743
ExecCloseIndices (resultRelInfo );
2740
2744
heap_close (resultRelInfo -> ri_RelationDesc , NoLock );
2741
2745
}
@@ -4726,30 +4730,3 @@ CreateCopyDestReceiver(void)
4726
4730
4727
4731
return (DestReceiver * ) self ;
4728
4732
}
4729
-
4730
- /*
4731
- * Start COPY FROM on foreign relation, if possible. If not, just do nothing.
4732
- */
4733
- static void InitForeignCopyFrom (EState * estate , ResultRelInfo * resultRelInfo ,
4734
- CopyState cstate , char * dest_relname )
4735
- {
4736
- if (resultRelInfo -> ri_FdwRoutine &&
4737
- FdwCopyFromIsSupported (resultRelInfo -> ri_FdwRoutine ))
4738
- {
4739
- resultRelInfo -> ri_FdwRoutine ->
4740
- BeginForeignCopyFrom (estate , resultRelInfo , cstate , dest_relname );
4741
- }
4742
- }
4743
-
4744
- /*
4745
- * Finish COPY FROM on foreign relation, if needed.
4746
- */
4747
- static void EndForeignCopyFrom (EState * estate , ResultRelInfo * resultRelInfo )
4748
- {
4749
- if (resultRelInfo -> ri_FdwRoutine &&
4750
- FdwCopyFromIsSupported (resultRelInfo -> ri_FdwRoutine ))
4751
- {
4752
- resultRelInfo -> ri_FdwRoutine -> EndForeignCopyFrom (
4753
- estate , resultRelInfo );
4754
- }
4755
- }
0 commit comments