2

I had reviewed this thread which covers performing a bulk insert using the mysql node module but with a very particular syntax that doesn't include the use of subqueries. I was wondering how I would perform a bulk insert using this module for a query like this.

db.query('insert into pizzas (qty, timeDayCityId) values (?, (select id from timeDayCity where time_id = ? and day_id = ? and city_id = ?)', [qty, time_id, day_id, city_id])

While I'm able to run this in the mysql module just fine over a loop, I was hoping for a speedier insert process, but can't seem to figure out how to adjust the syntax so it works for a bulk insert operation. Cheers.

Quilty Kim
  • 455
  • 1
  • 4
  • 18
  • I don't even see how this is a bulk insert. Are you saying you have some loop which would change the values of the parameters? – Tim Biegeleisen Oct 31 '17 at 05:10
  • while the loop itself doesn't change the paramters per iteration, yes, the parameters do change per iteration as I'm parsing data I received from an API call and then performing an insert operation. I'd prefer to work with a bulk insert over performing a bunch of separate insert operations over a loop. Thanks. – Quilty Kim Oct 31 '17 at 05:20
  • I don't see a nice way of doing this, so +1. See if you can somehow reduce the query to a simple `INSERT INTO ... SELECT`. – Tim Biegeleisen Oct 31 '17 at 05:27
  • I am also trying to solve the same problem. Any luck? – jbambrough May 12 '19 at 16:43

0 Answers0