MySQL Forums
Forum List  »  Performance

Re: Performance of ON DUPLICATE KEY and other options?
Posted by: Mark Modrall
Date: November 10, 2005 10:26AM

Hi Jaime...

No problem... Actually, in the comments for the ON DUPLICATE KEY UPDATE man page, there is a clue on how to do this. LAST_INSERT_ID() can also be explicitly set if you provide a parameter. The example in the man comments was to do something like this:

INSERT INTO table (a,b,c) SELECT ... ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
SELECT LAST_INSERT_ID();

taken together, the last SELECT will return the last id touched whether new or not.

You can execute the two statements together as a compound and then ExecuteScalar() to get the result, but there is a bug I have in (on the .Net connector at least) that Prepare() breaks if you have a compound statement.

If you're running MySql 5, you could also put the two statements in a stored procedure and execute that.

-Mark

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Performance of ON DUPLICATE KEY and other options?
1408
November 10, 2005 10:26AM


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.