Re: Performance of ON DUPLICATE KEY and other options?
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
Subject
Views
Written By
Posted
2236
September 23, 2005 09:20AM
1347
September 23, 2005 10:48AM
1421
September 23, 2005 10:56AM
1347
September 23, 2005 11:20AM
1486
September 23, 2005 11:38AM
1357
September 23, 2005 03:33PM
1355
September 23, 2005 04:25PM
1286
September 23, 2005 04:59PM
1505
September 26, 2005 02:30PM
1370
November 10, 2005 10:12AM
Re: Performance of ON DUPLICATE KEY and other options?
1408
November 10, 2005 10:26AM
1328
November 10, 2005 02:19PM
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.