John Hughes <jondo2010(at)gmail(dot)com> writes:
> The problem is that inserting into temp_holding takes more than a SECOND PER
> ROW!
Offhand I'd bet on the repeated computations of max(core_leads.id) as
being the bulk of the problem. That's completely broken anyway since
if concurrent insertions are happening there's no guarantee you'll
get the same result each time. Consider using a sequence to
generate these IDs, and doing just one nextval() not several per
trigger call.
regards, tom lane