-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Bulk insert with parameterized query #887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @salmanm , I'm not sure how I missed your issue on here. Can you provide some more details? Perhaps a code example? The main thing is I'm not quite sure what you mean by "when I try the same with query having multiple parameters". Here is an example of doing a bulk insert into the test table for two columns: var data = [[20,'test1'],[21,'test2']];
connection.query('INSERT INTO table (`id`,`value`) VALUES ?', [data], function(err, result) {
// ...
}); |
Hi, The example you showed, would replace "?" with say (2, 'val 1'), (2, 'val 1') ... but if I change the query to the following, It doesn't work.
The input array of arrays has same number of element, for eg. Is there something I should change in the input? |
Ah. Yes, bulk insert does not (yet) work for |
Oh ok. But I think without POINT also it wasn't working. It was trying to I'll check again. Thanks. -- Sent from my Android device.
|
Ah, ok. Did you try my code out? Can you perhaps actually post JavaScript code that can reproduce it? To know I'd have to actually see how it's called, but it sounds like you don't have enough array nesting (look at my example--the array of arrays is in an array itself in the |
Hi, No, I am aware about the array nesting, see my code sample below. Yes, I
However, this fails, (note the parameters in the query) connection.query('INSERT INTO tbl (id, name) VALUES (?, ?)', [[[1, 'aaa'],[1, 'bbb']]], function(err, rows, fields) { Array nesting looks fine here too. Ideally, it should replace each ? with BTW, I didn't get why the first one is made like this, I mean replacing one |
Ah yes, I see what you're thinking now. Yes, the behavior is not very intuitive. Personally I don't like how it's so complicated and think if there are any placeholders, one But back to what you're doing: I believe it's because you messed up the SQL syntax for inserts. Try the following (also it was nested too deep in arrays for this): connection.query('INSERT INTO tbl (id, name) VALUES (?), (?)', [[1, 'aaa'],[1, 'bbb']], function(err, rows, fields) { if (err) throw err; }); Is that what you're looking for? |
Kind of, but this also has a limitation, I should know how many rows I am On Wed, Aug 6, 2014 at 7:28 PM, Douglas Christopher Wilson <
Thanks. -Salman |
hm, sorry, I'm just not sure what you're asking. Your question now sounds like my first answer I gave would apply here. My answer with the question mark per row was based off your comment before that where you seemed like that's what you wanted. So, I'm just trying to say I'm just not sure what you're actually looking for here :( Can you post the query you want to use, the values array you want to give it, and the actual SQL you are expecting it to give you, maybe? |
Sorry if I am not able to explain it correctly. Here's the sample input and output. Query & Input:
Output: Actually, you already answered my question when you said 1) it doesn't support If the later one is supported, I think there won't be separate effort required to support Thanks. |
Gotcha. The main thing is we do not parse the SQL syntax, so the replacements cannot be very smart. There are actual SQL-building modules you can use if you need more advanced things. |
According to the documentation, sending array of arrays would do a bulk insert. However, when I try the same with query having multiple parameters, it fails, is there any issue with that? Is this feature already implemented?
in the meantime, I'll look at the source to find out what's wrong.
The text was updated successfully, but these errors were encountered: