Sqlalchemy adding multiple records and potential constraint violation
<p>I have table with unique contraint on one colum like:</p>

<pre><code>CREATE TABLE entity (
    id      INT NOT NULL AUTO_INCREMENT,
    zip_code    INT NOT NULL,
    entity_url  VARCHAR(255) NOT NULL,
    PRIMARY KEY (id),
    UNIQUE KEY ix_uniq_zip_code_entity_url (zip_code, entity_url)
);
</code></pre>

<p>and corresponding SQLAlchemy model. I adding a lot of records and do not want to commit session after each record. My assumption that better to call <code>session.add(new_record)</code> multiple times and one time <code>session.commit()</code>.</p>

<p>But while adding new records I could get <code>IntegrityError</code> because constraint is violated. It is normal situation and I want just skip such records insertion. But looks like I can only revert entire transaction.</p>

<p>Also I do not want to add another complex checks "get all records from database where zip_code in [...] and entity_url in [...] then drop matched data from records_to_insert".</p>

<p>Is there way to instuct SQLAlchemy drop records which violates constraint?</p>