I would like somebody to consider Petr Jelineks patch for worker.c from
here
(https://www.postgresql.org/message-id/619c557d-93e6-1833-1692-b010b176ff77%402ndquadrant.com)
I'm was facing the same issue with 10.1 and BEFORE INSERT OR UPDATE
triggers.
BR
Thomas Rosenstein