@@ -285,6 +285,7 @@ do_compile(FunctionCallInfo fcinfo,
285285int * in_arg_varnos = NULL ;
286286PLpgSQL_variable * * out_arg_variables ;
287287MemoryContext func_cxt ;
288+ PLpgSQL_trigtype fn_is_trigger ;
288289
289290/*
290291 * Setup the scanner input and error info.We assume that this function
@@ -352,11 +353,12 @@ do_compile(FunctionCallInfo fcinfo,
352353function -> resolve_option = plpgsql_variable_conflict ;
353354
354355if (is_dml_trigger )
355- function -> fn_is_trigger = PLPGSQL_DML_TRIGGER ;
356+ fn_is_trigger = PLPGSQL_DML_TRIGGER ;
356357else if (is_event_trigger )
357- function -> fn_is_trigger = PLPGSQL_EVENT_TRIGGER ;
358+ fn_is_trigger = PLPGSQL_EVENT_TRIGGER ;
358359else
359- function -> fn_is_trigger = PLPGSQL_NOT_TRIGGER ;
360+ fn_is_trigger = PLPGSQL_NOT_TRIGGER ;
361+ function -> fn_is_trigger = fn_is_trigger ;
360362
361363/*
362364 * Initialize the compiler, particularly the namespace stack. The
@@ -374,6 +376,7 @@ do_compile(FunctionCallInfo fcinfo,
374376sizeof (PLpgSQL_datum * )* datums_alloc );
375377datums_last = 0 ;
376378
379+ Assert (fn_is_trigger == function -> fn_is_trigger );
377380switch (function -> fn_is_trigger )
378381{
379382case PLPGSQL_NOT_TRIGGER :
@@ -537,9 +540,13 @@ do_compile(FunctionCallInfo fcinfo,
537540rettypeid == RECORDOID )
538541/* okay */ ;
539542else if (rettypeid == TRIGGEROID || rettypeid == EVTTRIGGEROID )
543+ {
540544ereport (ERROR ,
541545(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
542- errmsg ("trigger functions can only be called as triggers" )));
546+ errmsg ("trigger functions can only be called as triggers" ),
547+ errhint ("CALLED_AS_TRIGGER=%d CALLED_AS_EVENT_TRIGGER=%d" ,
548+ CALLED_AS_TRIGGER (fcinfo ),CALLED_AS_EVENT_TRIGGER (fcinfo ))));
549+ }
543550else
544551ereport (ERROR ,
545552(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),