ParoX
ParoX

Reputation: 5941

ON DUPLICATE KEY UPDATE every column except

I am using mysql through a socket, and I am updating 4000 records therefore I need to mass INSERT / UPDATE them to reduce network lag. The problem is that I have a column datetime_inserted that I want to set as NOW() when a record is first inserted, but never be replaced when it already exists, therefore REPLACE is not an option and I want to update the record, so IGNORE won't work.

I don't really understand the whole ON DUPLICATE KEY UPDATE but I want every column (40 or so) to update EXCEPT for datetime_inserted

How can I do this?

Upvotes: 0

Views: 218

Answers (1)

Vatev
Vatev

Reputation: 7590

INSERT INTO the_table (col1,col2,...,datetime_inserted) VALUES(value1,value2,...,NOW())
ON DUPLICATE KEY UPDATE SET col1=VALUES(col1), col2=VALUES(col2), ... #skip the datetime_inserted for the updates

Upvotes: 3

Related Questions