0

I'm trying to do a bulk insert to a mysql table doing something like this:

const query = 'INSERT INTO player 
                    (playerId, name, team, jersey, position, foot, dob) 
                VALUES (?,?,?,?,?) 
                    ON DUPLICATE KEY 
                        UPDATE playerId = ?, name = ?, 
                                team = ?, jersey = ?, 
                                position = ?, foot = ?, dob = ?;';

I'm sending a chunked array with the values, for example:

const players = [[...], [...], [...]]

and doing this to execute the query that I found here: How do I do a bulk insert in mySQL using node.js

await this.db.execute(query, [players]);

However I get this error:

ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE rentalId = ?, a' at line 1","

I tried different way to send the values, but still getting the same error, I saw one comment on the issue mentioned above saying I need to send it in this form: [[[],[]], [here is second question mark item]]

but I'm not sure how that will look.

any ideas?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149

0 Answers0