Fixes bug 1032851 - add a retry if we get a duplicate on UPSERT

This is to address a race condition where we have two instances of a processor (thread or process) that get ahold of the same crash at the same time. It's possible in this situation for the UPSERT calls to happen close enough together that both UPDATEs fail and both INSERTs are attempted, resulting in a "duplicate key" error on one of the INSERTs. In that situation, we just have the failed UPSERT call retry.
one of the things that I never remember about PG connections: when the initial IntegrityError happens, is the transaction "spoiled"?  Do you have to rollback to start a new transaction before using the connection again?