L
L
l4m3r2019-08-04 20:19:06
MySQL
l4m3r, 2019-08-04 20:19:06

Is mass insert/update + increment possible?

Let's say we have a table foo(name, count);.
I need to frequently increment the count counter by different name.
But in order not to bombard mysql with a bunch of queries continuously, I first collect a certain set of records for insert / update on the backend:

[
   'name1' => 235,
   'name2' => 1,
   'name4' => 3,
// ...
]

Question: is it possible to somehow insert all the names from the array with one request if they do not exist, and if they exist, add count to the specified value (235, 1, 3, ... each has its own)?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question