List:General Discussion« Previous MessageNext Message »
From:Fer C. Date:October 7 2009 5:12pm
Subject:Re: How to "REPLACE" updating when it's a subset of the primary key
what is duplicated or inserting otherwise?
View as plain text  
Thank you for your fast reply!

On Wed, Oct 7, 2009 at 6:25 PM, ewen fortune <ewen.fortune@stripped> wrote:
> Why not use INSERT ON DUPLICATE KEY UPDATE.
> http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html
>
>> So, If I want to insert-update the record "(a1,b2),b3" the two cases would be:
>>
>> a) record "(a1,a2),a3"  exists and has a matching "a1"
>> --update-to-->    "(a1,b2),b3"
>> b) there doesn't exist any record matching a1
>> ----insert--->      "(a1,b2),a3"
>
> So,
>
> INSERT INTO table (a,b,c) VALUES (1,2,3)
>  ON DUPLICATE KEY UPDATE b=2,c=3;

That has the same effect as REPLACE for me.
The primary key is "a,b" so, it's possible that there's a (1,4,5)
record already in the table that I want updated but INSERT ON
DUPLICATE KEY UPDATE will instead insert a (1,2,3) record (the "a"
field is the same but it still has a different "b" and thus it's a
different primary key, so it's not considered a duplicate).

--
Fernando
Thread
How to "REPLACE" updating when it's a subset of the primary key what is duplicated or inserting otherwise?Fer C.7 Oct
  • Re: How to "REPLACE" updating when it's a subset of the primary key what is duplicated or inserting otherwise?ewen fortune7 Oct
    • Re: How to "REPLACE" updating when it's a subset of the primary key what is duplicated or inserting otherwise?Fer C.7 Oct