catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

REPLACE INTO feature missing in Medoo. #318

Closed jezmck closed 3 years ago

jezmck commented 8 years ago

Note that I am not referring to Medoo's existing replace feature.

MySQL allows REPLACE INTO queries which update existing rows or insert new row into the database if matching ones don't exist.

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. https://dev.mysql.com/doc/refman/5.7/en/replace.html

This is a massively useful feature which could be implemented for non-MySQL DBs if required.

Note that I am not referring to Medoo's existing replace feature.

SyuTingSong commented 8 years ago

REPLACE INTO doesn't work fine with the foreign key constrains since it removes the row with duplicate key and insert new. I've moved to INSERT ... ON DUPLICATE KEY UPDATE syntax in MySQL. Poorly such syntax is supported only by MySQL.

jezmck commented 8 years ago

Is there documentation on how to use that syntax with Medoo? On 17 Nov 2015 4:53 am, "SyuTingSong" notifications@github.com wrote:

REPLACE INTO doesn't work fine with the foreign key constrains since it removes the row with duplicate key and insert new. I've moved to INSERT ... ON DUPLICATE KEY UPDATE syntax in MySQL. Poorly such syntax is supported only by MySQL.

— Reply to this email directly or view it on GitHub https://github.com/catfan/Medoo/issues/318#issuecomment-157267474.

SyuTingSong commented 8 years ago

It's a MySQL syntax, not supported by other DB. Medoo haven't provide a method to do that, you can call $medoo->query($sql) or $medoo->exec($sql) to run SQL directly.

interactiveRob commented 9 months ago

little confused here as this was closed by @catfan with no explanation. I assume this feature was not picked up?