MySQL Forums
Forum List  »  InnoDB

Re: Possible to do if .. then atomically without exceptions?
Posted by: Aftab Khan
Date: September 14, 2012 02:00AM

>* Query for x (where x has a unique index)
>* If x is not found, insert x

You could do it using single query:
INSERT IGNORE INTO `A` (name) VALUES ('Jones');

If you use the IGNORE keyword, errors that occur while executing the INSERT statement are treated as warnings instead. For example, without IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error and the statement is aborted. With IGNORE, the row still is not inserted, but no error is issued.



Edited 1 time(s). Last edit at 09/14/2012 07:33AM by Aftab Khan.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Possible to do if .. then atomically without exceptions?
798
September 14, 2012 02:00AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.