MySQL Forums
Forum List  »  InnoDB

IF exists, update, ELSE, insert? Need query help
Posted by: Ryan Peters
Date: November 11, 2008 02:38PM

I have an importer tool that currently executes queries in batches of 100 at a time using "INSERT IGNORE" with a couple columns set as unique. All is working well.

However, I want to modify it so that, if a record already exists (based off the unique columns), only update a couple of columns rather than replace the entire row, resulting in a new PK value. It essentially needs to update a portion of the row is it exists. If not, insert as normal. INSERT IGNORE will just ignore it obviously, and REPLACE INTO adds a new row - I just need to update the existing one.

How can I do this without incurring too much overhead? It works quite fast right now. My query looks like this:

insert ignore into (col1, col2, col3) values (1,2,3), (4,5,6), (7,8,9)...etc...

How can I modify this query with the logic stated above, and with the least overhead? Thanks!

Options: ReplyQuote


Subject
Views
Written By
Posted
IF exists, update, ELSE, insert? Need query help
6284
November 11, 2008 02:38PM


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.