Guido Niewerth <gniewerth@ocsgmbh.com> writes:
> As you can see there�s a huge runtime difference between the select query used in the trigger function and the one
runfrom the SQL editor.
contrib/auto_explain might be useful in seeing what's going on, in
particular it would tell us whether or not a different plan is being
used for the query inside the function.
regards, tom lane