@@ -294,7 +294,7 @@ static char *PLy_procedure_name(PLyProcedure *);
294294static void
295295PLy_elog (int ,const char * ,...)
296296__attribute__((format (printf ,2 ,3 )));
297- static void PLy_get_spi_error_data (PyObject * exc ,char * * hint ,char * * query ,int * position );
297+ static void PLy_get_spi_error_data (PyObject * exc ,char * * detail , char * * hint ,char * * query ,int * position );
298298static char * PLy_traceback (int * );
299299
300300static void * PLy_malloc (size_t );
@@ -3551,7 +3551,7 @@ PLy_spi_exception_set(ErrorData *edata)
35513551if (!spierror )
35523552gotofailure ;
35533553
3554- spidata = Py_BuildValue ("(zzi)" ,edata -> hint ,
3554+ spidata = Py_BuildValue ("(zzzi)" , edata -> detail ,edata -> hint ,
35553555edata -> internalquery ,edata -> internalpos );
35563556if (!spidata )
35573557gotofailure ;
@@ -3586,13 +3586,14 @@ PLy_elog(int elevel, const char *fmt,...)
35863586int xlevel ;
35873587StringInfoData emsg ;
35883588PyObject * exc ,* val ,* tb ;
3589+ char * detail = NULL ;
35893590char * hint = NULL ;
35903591char * query = NULL ;
35913592int position = 0 ;
35923593
35933594PyErr_Fetch (& exc ,& val ,& tb );
35943595if (exc != NULL && PyErr_GivenExceptionMatches (val ,PLy_exc_spi_error ))
3595- PLy_get_spi_error_data (val ,& hint ,& query ,& position );
3596+ PLy_get_spi_error_data (val ,& detail , & hint ,& query ,& position );
35963597PyErr_Restore (exc ,val ,tb );
35973598
35983599xmsg = PLy_traceback (& xlevel );
@@ -3626,6 +3627,7 @@ PLy_elog(int elevel, const char *fmt,...)
36263627else
36273628ereport (elevel ,
36283629(errmsg ("PL/Python: %s" ,xmsg ),
3630+ (detail ) ?errdetail ("%s" ,detail ) :0 ,
36293631 (hint ) ?errhint ("%s" ,hint ) :0 ,
36303632 (query ) ?internalerrquery (query ) :0 ,
36313633 (position ) ?internalerrposition (position ) :0 ));
@@ -3650,15 +3652,15 @@ PLy_elog(int elevel, const char *fmt,...)
36503652 * Extract the error data from a SPIError
36513653 */
36523654static void
3653- PLy_get_spi_error_data (PyObject * exc ,char * * hint ,char * * query ,int * position )
3655+ PLy_get_spi_error_data (PyObject * exc ,char * * detail , char * * hint ,char * * query ,int * position )
36543656{
36553657PyObject * spidata = NULL ;
36563658
36573659spidata = PyObject_GetAttrString (exc ,"spidata" );
36583660if (!spidata )
36593661gotocleanup ;
36603662
3661- if (!PyArg_ParseTuple (spidata ,"zzi" ,hint ,query ,position ))
3663+ if (!PyArg_ParseTuple (spidata ,"zzzi" , detail ,hint ,query ,position ))
36623664gotocleanup ;
36633665
36643666cleanup :