Re: ignore unique violation OR check row exists

From: Zdravko Balorda <zdravko(dot)balorda(at)siix(dot)com>
To: Samuel Gendler <sgendler(at)ideasculptor(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: ignore unique violation OR check row exists
Date: 2012-01-04 12:33:55
Message-ID: 4F044733.6020007@siix.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Samuel Gendler wrote:
>
>
> On Wed, Jan 4, 2012 at 1:57 AM, Zdravko Balorda
> <zdravko(dot)balorda(at)siix(dot)com <mailto:zdravko(dot)balorda(at)siix(dot)com>> wrote:
> Take it out of transaction. Why is there a transaction in the first
> place?
> If transaction is needed, ok, but take these inserts out and
> everything will
> work as it should. Ignoring UNIQUE VIOLATION or any other error
> defeats the very
> purpose of transaction. That's why you can't ignore it.
>
>
> Unfortunately, bulk inserts are much slower when they don't occur in a
> transaction. Try inserting 1 million rows with auto commit enabled vs 1
> million rows in 1 transaction, or even 10 or 100 transactions. The
> difference is enormous. The bulk insert into an unconstrained table and
> then pulling just the new rows over into the destination table in a
> single transaction is definitely the most effective way to do this.
>

I do a lot of bulk inserts. What helps is dropping indexes before insert
and recreating it after. Probably you need to better organize data to
avoid having primary keys on a table with a lots of data.

Zdravko

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message rverghese 2012-01-04 17:34:35 Re: ignore unique violation OR check row exists
Previous Message Misa Simic 2012-01-04 10:23:29 Re: ignore unique violation OR check row exists