Thread: Insert with possible constraint violations?
Hello. What is the proper way of inserting stuff into a table with two fields (A and B) with a constraint unique(A,B) and you suspect you will get some unique constraint violations? Should I just do INSERT etc... and just ignore the answer? Or do a select first and see if it returned any record? Or is there a way of way to write a function that do the INSERT but catches the error and do not write anything to the log about the violation? In that case, what would such a function look like? To me it seems that writing error messages to log files is not very efficient. So what would you suggest me doing?
> I'm not sure I have enough knowledge to answer you so I think > I'm replying to you personally but I think it would help you get > your answer if you described what you would like to do with > records that violate the unique(a,b) constraint. If they violate, just ignore them. mysql have a insert ignore that tries to insert and ignore any error and this is just the thing. I could select and see if it is already there, but that seems a little unessecery.