@@ -78,7 +78,7 @@ static ObjectAddress create_table_using_stmt(CreateStmt *create_stmt,
78
78
static void copy_foreign_keys (Oid parent_relid , Oid partition_oid );
79
79
static void postprocess_child_table_and_atts (Oid parent_relid , Oid partition_relid );
80
80
81
- static Oid text2regprocedure (text * proname_args );
81
+ static Oid text_to_regprocedure (text * proname_args );
82
82
83
83
static Constraint * make_constraint_common (char * name , Node * raw_expr );
84
84
@@ -400,19 +400,20 @@ create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type)
400
400
{
401
401
ErrorData * edata ;
402
402
403
+ /* Simply rethrow ERROR if we're in backend */
404
+ if (!IsBackgroundWorker )
405
+ PG_RE_THROW ();
406
+
403
407
/* Switch to the original context & copy edata */
404
408
MemoryContextSwitchTo (old_mcxt );
405
409
edata = CopyErrorData ();
406
410
FlushErrorState ();
407
411
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 ));
416
417
417
418
FreeErrorData (edata );
418
419
@@ -1391,34 +1392,6 @@ make_int_value_struct(int int_val)
1391
1392
return val ;
1392
1393
}
1393
1394
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
-
1422
1395
1423
1396
/*
1424
1397
* ---------------------
@@ -1467,14 +1440,14 @@ invoke_init_callback_internal(init_callback_params *cb_params)
1467
1440
/* Cache init_callback's Oid */
1468
1441
if (init_cb_datum )
1469
1442
{
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 ));
1472
1445
1473
1446
if (!RegProcedureIsValid (cb_params -> callback ))
1474
1447
ereport (ERROR ,
1475
1448
(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 ))));
1478
1451
}
1479
1452
else
1480
1453
cb_params -> callback = InvalidOid ;
@@ -1609,3 +1582,31 @@ validate_part_callback(Oid procid, bool emit_error)
1609
1582
1610
1583
return is_ok ;
1611
1584
}
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
+ }
0 commit comments