“INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”

后端 未结 12 2471
孤街浪徒
孤街浪徒 2020-11-21 04:30

While executing an INSERT statement with many rows, I want to skip duplicate entries that would otherwise cause failure. After some research, my options appear

12条回答
  •  孤街浪徒
    2020-11-21 04:57

    I know this is old, but I'll add this note in case anyone else (like me) arrives at this page while trying to find information on INSERT..IGNORE.

    As mentioned above, if you use INSERT..IGNORE, errors that occur while executing the INSERT statement are treated as warnings instead.

    One thing which is not explicitly mentioned is that INSERT..IGNORE will cause invalid values will be adjusted to the closest values when inserted (whereas invalid values would cause the query to abort if the IGNORE keyword was not used).

提交回复
热议问题