From 1dc45adefa076e9377718ee9529b375a70108734 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 26 Oct 2026 17:15:27 -0400 Subject: [PATCH] Initialize FOUND to false in PL/pgSQL event trigger functions. The documentation says that FOUND starts out false within each PL/pgSQL function call. plpgsql_exec_function() and plpgsql_exec_trigger() do set it so, but plpgsql_exec_event_trigger() did not, leaving it NULL until the first statement that sets it. Fix this by initializing FOUND to false, as the other two entry points do. While at it, also set estate.err_text to "during function entry" during this action and the subsequent instrumentation plugin call, again to match the other two routines. Back-patch to v19, but no further. It seems unlikely that any user code is depending on the current behavior, but just in case, let's not touch the stable branches. Author: Jeevan Chalke Reviewed-by: Tom Lane Discussion: https://postgr.es/m/CAM2+6=U_=hZmgs1v1JJ-XJk2bpbfqQPP9MNRDbp5RoEsOW8xsQ@mail.gmail.com Backpatch-through: 19 --- src/pl/plpgsql/src/pl_exec.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c index bc1667f7a13..e857daa6745 100644 --- a/src/pl/plpgsql/src/pl_exec.c +++ b/src/pl/plpgsql/src/pl_exec.c @@ -1199,6 +1199,13 @@ plpgsql_exec_event_trigger(PLpgSQL_function *func, EventTriggerData *trigdata) estate.err_text = gettext_noop("during initialization of execution state"); copy_plpgsql_datums(&estate, func); + estate.err_text = gettext_noop("during function entry"); + + /* + * Set the magic variable FOUND to false + */ + exec_set_found(&estate, false); + /* * Let the instrumentation plugin peek at this function */