MySQLism: avoid using MySQL REPLACE syntax
Last updated on
8 September 2016
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
MySQL allows running INSERT or UPDATE in one single query, which is extremely useful.
REPLACE works exactly like INSERT, except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is deleted before the new row is inserted.
Unfortunately, this MySQL syntax is not supported by any other database. It should be avoided.
Try to use a combination of INSERTs and UPDATEs.
Reference: MySQL replace command.
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.