Re: bulk insert unique contraint - Mailing list pgsql-general

From Andy Colson
Subject Re: bulk insert unique contraint
Date
Msg-id 52C18C5E.9080507@squeakycode.net
Whole thread Raw
In response to bulk insert unique contraint  ("Janek Sendrowski" <janek12@web.de>)
List 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'musing 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


pgsql-general by date:

Previous
From: "Janek Sendrowski"
Date:
Subject: bulk insert unique contraint
Next
From: Joey Quinn
Date:
Subject: postgres for disconnected environment