@@ -718,43 +718,23 @@ prepare_rri_for_copy(ResultRelInfoHolder *rri_holder,
718718 /*
719719 * If this Postgres has no idea about shardman, behave as usual:
720720 * vanilla Postgres doesn't support COPY FROM to foreign partitions.
721- * However, shardman patches to core extend FDW API to allow it,
722- * though currently postgres_fdw does so in a bit perverted way: we
723- * redirect COPY FROM to parent table on foreign server, assuming it
724- * exists, and let it direct tuple to proper partition. This is
725- * because otherwise we have to modify logic of managing connections
726- * in postgres_fdw and keep many connections open to one server from
727- * one backend.
721+ * However, shardman patches to core extend FDW API to allow it.
728722 */
729- #ifndef PG_SHARDMAN
730- goto bail_out ; /* to avoid 'unused label' warning */
731- #else
732- { /* separate block to avoid 'unused var' warnings */
723+ #ifdef PG_SHARDMAN
724+ /* shardman COPY FROM requested? */
725+ if (* find_rendezvous_variable (
726+ "shardman_pathman_copy_from_rendezvous" ) != NULL &&
727+ FdwCopyFromIsSupported (fdw_routine ))
728+ {
733729 CopyState cstate = (CopyState ) rps_storage -> callback_arg ;
734- ResultRelInfo * parent_rri ;
735- const char * parent_relname ;
736- EState * estate ;
737-
738- /* shardman COPY FROM requested? */
739- if (* find_rendezvous_variable (
740- "shardman_pathman_copy_from_rendezvous" ) == NULL )
741- goto bail_out ;
742-
743- estate = rps_storage -> estate ;
744- parent_rri = rps_storage -> saved_rel_info ;
745- parent_relname = psprintf (
746- "%s.%s" , "public" ,
747- quote_identifier (RelationGetRelationName (parent_rri -> ri_RelationDesc )));
748- if (!FdwCopyFromIsSupported (fdw_routine ))
749- ereport (ERROR ,
750- (errcode (ERRCODE_WRONG_OBJECT_TYPE ),
751- errmsg ("FDW adapter for relation \"%s\" doesn't support COPY FROM" ,
752- RelationGetRelationName (rri -> ri_RelationDesc ))));
753- fdw_routine -> BeginForeignCopyFrom (estate , rri , cstate , parent_relname );
730+ ResultRelInfo * parent_rri = rps_storage -> saved_rel_info ;
731+ EState * estate = rps_storage -> estate ;
732+
733+ fdw_routine -> BeginForeignCopyFrom (estate , rri , cstate , parent_rri );
754734 return ;
755735 }
756736#endif
757- bail_out :
737+
758738 elog (ERROR , "cannot copy to foreign partition \"%s\"" ,
759739 get_rel_name (RelationGetRelid (rri -> ri_RelationDesc )));
760740 }
0 commit comments