What does upsert actually return? #34979
-
Hi, I have 5 db records (mysql) with given PK (compound, on 2 columns). And I have 5 records that require update / insert. If I run upsert on all records it returns (int) 10 affected rows. If I delete one db record (4) and upsert 5 records it returns (int) 9. Shouldn't it be 5 in both cases? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@xorock the So, for instance, if you're using mysql, here's how it calculates the number of affected rows (direct quote from docs):
|
Beta Was this translation helpful? Give feedback.
-
This information should really be included in the documentation https://laravel.com/docs/10.x/eloquent#upserts |
Beta Was this translation helpful? Give feedback.
@xorock the
upsert
function returns what the database engine returns for upserts. This can be specific to the DB engine you're using because upserts aren't really SQL standards.So, for instance, if you're using mysql, here's how it calculates the number of affected rows (direct quote from docs):