sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) duplicate key value violates unique constraint already exists. already exists. code example

Example 1: ERROR: duplicate key value violates unique constraint statuslogs_pkey DETAIL: Key (id)=(1621) already exists.

How to reset postgres' primary key sequence when it falls out of sync?

Example 2: duplicate key value violates unique constraint "pg_type_typname_nsp_index"

I was reading this. It seems this error rises when you are creating/updating the same table with parallel processing. I understand it depends because of this (as explained on the google group discussion).

So I think it depend from PostgreSQL itself and not from the connection driver or the module used for the multiprocessing.

Well, Actually, the only way I found to solve this is to create chunks big enough to have back a writing process slower than the calculation itself. With bigger chunks this error doesn't rise.

Tags:

Sql Example