@@ -78,7 +78,7 @@ static ObjectAddress create_table_using_stmt(CreateStmt *create_stmt,
7878static void copy_foreign_keys (Oid parent_relid ,Oid partition_oid );
7979static void postprocess_child_table_and_atts (Oid parent_relid ,Oid partition_relid );
8080
81- static Oid text2regprocedure (text * proname_args );
81+ static Oid text_to_regprocedure (text * proname_args );
8282
8383static Constraint * make_constraint_common (char * name ,Node * raw_expr );
8484
@@ -400,19 +400,20 @@ create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type)
400400{
401401ErrorData * edata ;
402402
403+ /* Simply rethrow ERROR if we're in backend */
404+ if (!IsBackgroundWorker )
405+ PG_RE_THROW ();
406+
403407/* Switch to the original context & copy edata */
404408MemoryContextSwitchTo (old_mcxt );
405409edata = CopyErrorData ();
406410FlushErrorState ();
407411
408- if (IsBackgroundWorker )
409- ereport (LOG ,
410- (errmsg ("create_partitions_internal(): %s [%u]" ,edata -> message ,MyProcPid ),
411- (edata -> detail ) ?errdetail ("%s" ,edata -> detail ) :0 ));
412- else
413- ereport (ERROR ,
414- (errmsg ("create_partitions_internal(): %s" ,edata -> message ),
415- (edata -> detail ) ?errdetail ("%s" ,edata -> detail ) :0 ));
412+ /* Produce log message if we're in BGW */
413+ ereport (LOG ,
414+ (errmsg (CppAsString (create_partitions_for_value_internal )": %s [%u]" ,
415+ edata -> message ,MyProcPid ),
416+ (edata -> detail ) ?errdetail ("%s" ,edata -> detail ) :0 ));
416417
417418FreeErrorData (edata );
418419
@@ -1391,34 +1392,6 @@ make_int_value_struct(int int_val)
13911392return val ;
13921393}
13931394
1394- /*
1395- * Utility function that converts signature of procedure into regprocedure.
1396- *
1397- * Precondition: proc_signature != NULL.
1398- *
1399- * Returns InvalidOid if proname_args is not found.
1400- * Raise error if it's incorrect.
1401- */
1402- static Oid
1403- text2regprocedure (text * proc_signature )
1404- {
1405- FunctionCallInfoData fcinfo ;
1406- Datum result ;
1407-
1408- InitFunctionCallInfoData (fcinfo ,NULL ,1 ,InvalidOid ,NULL ,NULL );
1409-
1410- #if PG_VERSION_NUM >=90600
1411- fcinfo .arg [0 ]= PointerGetDatum (proc_signature );
1412- #else
1413- fcinfo .arg [0 ]= CStringGetDatum (text_to_cstring (proc_signature ));
1414- #endif
1415- fcinfo .argnull [0 ]= false;
1416-
1417- result = to_regprocedure (& fcinfo );
1418-
1419- return DatumGetObjectId (result );
1420- }
1421-
14221395
14231396/*
14241397 * ---------------------
@@ -1467,14 +1440,14 @@ invoke_init_callback_internal(init_callback_params *cb_params)
14671440/* Cache init_callback's Oid */
14681441if (init_cb_datum )
14691442{
1470- cb_params -> callback = text2regprocedure (
1471- DatumGetTextP (init_cb_datum ));
1443+ /* Try fetching callback's Oid */
1444+ cb_params -> callback = text_to_regprocedure ( DatumGetTextP (init_cb_datum ));
14721445
14731446if (!RegProcedureIsValid (cb_params -> callback ))
14741447ereport (ERROR ,
14751448(errcode (ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION ),
1476- errmsg ("callback function \"%s\"doesn't exist" ,
1477- DatumGetCString (init_cb_datum ))));
1449+ errmsg ("callback function \"%s\"does not exist" ,
1450+ TextDatumGetCString (init_cb_datum ))));
14781451}
14791452else
14801453cb_params -> callback = InvalidOid ;
@@ -1609,3 +1582,31 @@ validate_part_callback(Oid procid, bool emit_error)
16091582
16101583return is_ok ;
16111584}
1585+
1586+ /*
1587+ * Utility function that converts signature of procedure into regprocedure.
1588+ *
1589+ * Precondition: proc_signature != NULL.
1590+ *
1591+ * Returns InvalidOid if proname_args is not found.
1592+ * Raise error if it's incorrect.
1593+ */
1594+ static Oid
1595+ text_to_regprocedure (text * proc_signature )
1596+ {
1597+ FunctionCallInfoData fcinfo ;
1598+ Datum result ;
1599+
1600+ InitFunctionCallInfoData (fcinfo ,NULL ,1 ,InvalidOid ,NULL ,NULL );
1601+
1602+ #if PG_VERSION_NUM >=90600
1603+ fcinfo .arg [0 ]= PointerGetDatum (proc_signature );
1604+ #else
1605+ fcinfo .arg [0 ]= CStringGetDatum (text_to_cstring (proc_signature ));
1606+ #endif
1607+ fcinfo .argnull [0 ]= false;
1608+
1609+ result = to_regprocedure (& fcinfo );
1610+
1611+ return DatumGetObjectId (result );
1612+ }