Better Postgres primary key constraint violation detection