@@ -180,9 +180,6 @@ static void CopySendInt32(CopyState cstate, int32 val);
180180static bool CopyGetInt32 (CopyState cstate , int32 * val );
181181static void CopySendInt16 (CopyState cstate , int16 val );
182182static 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 );
186183
187184
188185/*
@@ -2314,7 +2311,6 @@ CopyFrom(CopyState cstate)
23142311 TupleTableSlot * partition_tuple_slot ;
23152312 int num_parted ,
23162313 num_partitions ;
2317- int i ;
23182314
23192315 ExecSetupPartitionTupleRouting (cstate -> rel ,
23202316 1 ,
@@ -2351,16 +2347,15 @@ CopyFrom(CopyState cstate)
23512347 gettext_noop ("could not convert row type" ));
23522348 }
23532349 }
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- }
23602350 }
23612351
23622352 /* 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+ }
23642359
23652360 /*
23662361 * It's more efficient to prepare a bunch of tuples for insertion, and
@@ -2490,6 +2485,12 @@ CopyFrom(CopyState cstate)
24902485 saved_resultRelInfo = resultRelInfo ;
24912486 resultRelInfo = cstate -> partitions + leaf_part_index ;
24922487
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+
24932494 /*
24942495 * For ExecInsertIndexTuples() to work on the partition's indexes
24952496 */
@@ -2710,7 +2711,12 @@ CopyFrom(CopyState cstate)
27102711 /*
27112712 * Shut down FDW.
27122713 */
2713- EndForeignCopyFrom (estate , resultRelInfo );
2714+ if (resultRelInfo -> ri_FdwRoutine &&
2715+ FdwCopyFromIsSupported (resultRelInfo -> ri_FdwRoutine ))
2716+ {
2717+ resultRelInfo -> ri_FdwRoutine -> EndForeignCopyFrom (
2718+ estate , resultRelInfo );
2719+ }
27142720
27152721 /* Close all the partitioned tables, leaf partitions, and their indices */
27162722 if (cstate -> partition_dispatch_info )
@@ -2734,8 +2740,6 @@ CopyFrom(CopyState cstate)
27342740 {
27352741 ResultRelInfo * resultRelInfo = cstate -> partitions + i ;
27362742
2737- EndForeignCopyFrom (estate , resultRelInfo );
2738-
27392743 ExecCloseIndices (resultRelInfo );
27402744 heap_close (resultRelInfo -> ri_RelationDesc , NoLock );
27412745 }
@@ -4726,30 +4730,3 @@ CreateCopyDestReceiver(void)
47264730
47274731 return (DestReceiver * ) self ;
47284732}
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