Re: bulk insert unique contraint

From: Andy Colson <andy(at)squeakycode(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: bulk insert unique contraint
Date: 2013-12-30 15:08:14
Message-ID: 52C18C5E.9080507@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 12/30/2013 8:14 AM, Janek Sendrowski wrote:
> Hi,
>
> I want to insert data in my table and I want to insert the rows, which don't violates the unique contraint of my id. I'm using a 64bit hash for my it.
> If I do one insert statement, which inserts many rows it doesn't do anything if one row violates the unique contraint.
> Is there a faster way than using multiple insert statements?
>
> Janek
>
>

You could:

create table junk (like main);
copy to junk ...;
create index junkpk on junk(uid);
-- _not_ a unique index, optional
analyze junk;
select uid, count(*) from junk group by uid;
-- do something about the dups
insert into main select * from junk;
drop table junk;

-Andy

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joey Quinn 2013-12-30 15:37:45 postgres for disconnected environment
Previous Message Janek Sendrowski 2013-12-30 14:14:00 bulk insert unique contraint