How to ignore "Unique index or primary key violation"?

457 views
Skip to first unread message

Johannes Schneider

unread,
Aug 8, 2012, 9:13:21 AM8/8/12
to h2-da...@googlegroups.com
Hi guys,

I have a table with a unique index (id + time stamp). In this table I am storing a lot of values I receive from another service.
I am storing the data using a prepared statement in batches of about 400 entries.

Unfortunately this service might provide me with duplicate data. Now I just want to ignore those duplicate data (since it already exists within the db).


Of course I run into a  lot of "Unique index or primary key violation". That exceptions fails my complete transaction. But I just want the two or three problematic entries ignored...
I could add each of the entries within its own transaction. But I fear the performance penalty...

Any ideas how that could be solved?



Steve McLeod

unread,
Aug 9, 2012, 6:57:31 AM8/9/12
to h2-da...@googlegroups.com
I think you need to use the MERGE command instead of the INSERT command. Docs for MERGE are here:

Johannes Schneider

unread,
Aug 12, 2012, 3:32:54 PM8/12/12
to h2-da...@googlegroups.com
Great. Thanks for that hint. 
Reply all
Reply to author
Forward
0 new messages