user813720
user813720

Reputation: 451

how to get number of rows updated and inserted from mysql

I'm doing large number of:

INSERT.... ON DUPLICATE KEY UPDATE

queries and I want to find out the number of rows affected, ideally the number updated and the number inserted.

At the moment I'm using ROW_COUNT() but that counts as 2 from the above sql if the row is updated or 1 if it is inserted.

Is there a way to find this from a mysql function?

Upvotes: 0

Views: 424

Answers (1)

safarov
safarov

Reputation: 7804

With ON DUPLICATE KEY UPDATE, the affected-rows value is 1, if update its 2. From this you can determine how many rows inserted successfully and how many are updated

Upvotes: 1

Related Questions