@@ -74,6 +74,8 @@ static ObjectAddress create_table_using_stmt(CreateStmt *create_stmt,
74
74
static void copy_foreign_keys (Oid parent_relid ,Oid partition_oid );
75
75
static void postprocess_child_table_and_atts (Oid parent_relid ,Oid partition_relid );
76
76
77
+ static Oid text_to_regprocedure (text * proname_args );
78
+
77
79
static Constraint * make_constraint_common (char * name ,Node * raw_expr );
78
80
79
81
static Value make_string_value_struct (char * str );
@@ -406,13 +408,20 @@ create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type)
406
408
{
407
409
ErrorData * edata ;
408
410
411
+ /* Simply rethrow ERROR if we're in backend */
412
+ if (!IsBackgroundWorker )
413
+ PG_RE_THROW ();
414
+
409
415
/* Switch to the original context & copy edata */
410
416
MemoryContextSwitchTo (old_mcxt );
411
417
edata = CopyErrorData ();
412
418
FlushErrorState ();
413
419
414
- elog (LOG ,"create_partitions_internal(): %s [%u]" ,
415
- edata -> message ,MyProcPid );
420
+ /* Produce log message if we're in BGW */
421
+ ereport (LOG ,
422
+ (errmsg (CppAsString (create_partitions_for_value_internal )": %s [%u]" ,
423
+ edata -> message ,MyProcPid ),
424
+ (edata -> detail ) ?errdetail ("%s" ,edata -> detail ) :0 ));
416
425
417
426
FreeErrorData (edata );
418
427
@@ -1466,14 +1475,26 @@ invoke_init_callback_internal(init_callback_params *cb_params)
1466
1475
/* Search for init_callback entry in PATHMAN_CONFIG_PARAMS */
1467
1476
if (read_pathman_params (parent_oid ,param_values ,param_isnull ))
1468
1477
{
1469
- Datum init_cb_datum ;/*Oid of init_callback */
1478
+ Datum init_cb_datum ;/*signature of init_callback */
1470
1479
AttrNumber init_cb_attno = Anum_pathman_config_params_init_callback ;
1471
1480
1472
- /* Extract Datum storing callback'sOid */
1481
+ /* Extract Datum storing callback'ssignature */
1473
1482
init_cb_datum = param_values [init_cb_attno - 1 ];
1474
1483
1475
1484
/* Cache init_callback's Oid */
1476
- cb_params -> callback = DatumGetObjectId (init_cb_datum );
1485
+ if (init_cb_datum )
1486
+ {
1487
+ /* Try fetching callback's Oid */
1488
+ cb_params -> callback = text_to_regprocedure (DatumGetTextP (init_cb_datum ));
1489
+
1490
+ if (!RegProcedureIsValid (cb_params -> callback ))
1491
+ ereport (ERROR ,
1492
+ (errcode (ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION ),
1493
+ errmsg ("callback function \"%s\" does not exist" ,
1494
+ TextDatumGetCString (init_cb_datum ))));
1495
+ }
1496
+ else
1497
+ cb_params -> callback = InvalidOid ;
1477
1498
cb_params -> callback_is_cached = true;
1478
1499
}
1479
1500
}
@@ -1619,3 +1640,31 @@ validate_part_callback(Oid procid, bool emit_error)
1619
1640
1620
1641
return is_ok ;
1621
1642
}
1643
+
1644
+ /*
1645
+ * Utility function that converts signature of procedure into regprocedure.
1646
+ *
1647
+ * Precondition: proc_signature != NULL.
1648
+ *
1649
+ * Returns InvalidOid if proname_args is not found.
1650
+ * Raise error if it's incorrect.
1651
+ */
1652
+ static Oid
1653
+ text_to_regprocedure (text * proc_signature )
1654
+ {
1655
+ FunctionCallInfoData fcinfo ;
1656
+ Datum result ;
1657
+
1658
+ InitFunctionCallInfoData (fcinfo ,NULL ,1 ,InvalidOid ,NULL ,NULL );
1659
+
1660
+ #if PG_VERSION_NUM >=90600
1661
+ fcinfo .arg [0 ]= PointerGetDatum (proc_signature );
1662
+ #else
1663
+ fcinfo .arg [0 ]= CStringGetDatum (text_to_cstring (proc_signature ));
1664
+ #endif
1665
+ fcinfo .argnull [0 ]= false;
1666
+
1667
+ result = to_regprocedure (& fcinfo );
1668
+
1669
+ return DatumGetObjectId (result );
1670
+ }