datainsert is throwing an error due to a preexisting primary key. How can I make it keep going on error?

1 view (last 30 days)
In using datainsert, I am inserting about 50k rows into my database (mySQL,JDBC). My problem is that I keep on getting thrown error messages when there is a repeat primary key, interrupting and stopping my insertion.
I would like it to behave such that IF it tries to insert and fails, it simply moves on in the insertion. I see a few solutions:
  1. be informed of a feature of datainsert I was unaware of that get it to behave like this
  2. use a dynamicSQL query instead, since these continue even if an error is thrown
  3. perhaps fastinsert does not behave like this
  4. import all primary keys from the table, do the setdiff function and THEN datainsert. This is computer intensive as my database is too big for this to be a reasonable option.
  1 Comment
Will Kinsman
Will Kinsman on 28 Apr 2016
I have thought of a fifth solution that might be ideal. Datainserts seem to start at the bottom row and work up. I loop that says "while my row insertion cell array is not empty, keep trying to insert and on failure (catch) delete the last row".
This is not ideal as a lot of rows will may need to be deleted until the error one is reached but is at least a start. Let me know if anyone has any ideas.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!