luqita
luqita

Reputation: 4087

REPLACE into keeping a value

I want to make a replace into in a table where cust_id is the primary key, but I do not want to modify the date field. So, a normal insert on this table would look like:

    REPLACE INTO emails(cust_id, email, date) 
VALUES(55, '[email protected]', '2011-08-07 00:00');

Now, without having to modify the date field, it would be something such as:

REPLACE INTO emails(cust_id, email, date) 
VALUES(55, '[email protected]', date.value?);

But how do I exactly keep the date value?

Upvotes: 4

Views: 6254

Answers (2)

ajreal
ajreal

Reputation: 47321

insert ignore will skip insertion if any duplication

if you need to update certain fields ,
you can do

insert into some_table values (...)
on duplicate update email=?;

Upvotes: 5

Brian Glaz
Brian Glaz

Reputation: 15686

Short answer, You can't keep the dates that way. from Mysql documentation

Values for all columns are taken from the values specified in the REPLACE statement. Any missing columns are set to their default values, just as happens for INSERT. You cannot refer to values from the current row and use them in the new row

perhaps you want to use http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html instead.

Upvotes: 7

Related Questions