-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
Error on bulk insert with execute() #1244
Comments
your query ( including "?" symbols ) must be a valid input for PREPARE command, which is likely isn't also number of placeholders should be exactly the same as number of parameters.
|
Hi! I have a similar issue, makes me really mad. I'd go with option1: just using a query. table DDLCREATE TABLE tmp_throughput_onair_4g_50
(
id INT AUTO_INCREMENT PRIMARY KEY,
cell_id_4g INT NOT NULL,
eov POINT NOT NULL,
throughput INT NOT NULL,
created_at DATETIME NULL,
updated_at DATETIME NULL
) COLLATE = utf8mb4_unicode_ci;
CREATE INDEX tmp_throughput_onair_4g_50_cell_id_4g ON tmp_throughput_onair_4g_50 (cell_id_4g);
CREATE SPATIAL INDEX tmp_throughput_onair_4g_50_eov ON tmp_throughput_onair_4g_50 (eov);
CREATE INDEX tmp_throughput_onair_4g_50_throughput ON tmp_throughput_onair_4g_50 (throughput);
const promisePool = mysql.createPool(config).promisePool;
const sql = `insert into tmp_throughput_onair_4g_50
(cell_id_4g,eov,throughput,created_At,updated_At)
values (?,POINT(?, ?),?,?,?)`
const rows = [
[
"93",
"221325",
"680975",
"16",
"2022-04-07T19:51:47.202Z",
"2022-04-07T19:51:47.202Z"
],
[
"93",
"221375",
"680975",
"14",
"2022-04-07T19:51:47.203Z",
"2022-04-07T19:51:47.203Z"
]
];
await promisePool.query(sql, rows) and it throws:
What do I miss? |
to me it looks that sql query after parameters interpolation still contains some |
No. It seems that the whole first row (row[0]) is expanded by the first placeholder and don't know why. Six question mark, each row has 6 elements. |
it doesn't work like that. You have 2 elements array as parameters list, first goes as first |
So, is there a way to bulk insert say 10000 rows, which contain a POINT like I provided in the example? I thought if you provide an array in the second arg of query, it will insert one row for one element in the array. |
Maybe my question should go to #234 |
@pihentagy have a look at this example: class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
toSqlString() {
return `POINT(${this.x},${this.y})`;
}
}
const sql = /*sql*/ `
insert into tmp_throughput_onair_4g_50
(cell_id_4g,eov,throughput,created_At,updated_At)
values ?
`;
const rows = [
[[
'93',
new Point(221325, 680975),
'16',
new Date('2022-04-07T19:51:47.202Z'),
new Date('2022-04-07T19:51:47.202Z'),
],
[
'93',
new Point(221375, 680975),
'14',
new Date('2022-04-07T19:51:47.203Z'),
new Date('2022-04-07T19:51:47.203Z'),
]]
];
await conn.query(sql, rows); See https://github.com/mysqljs/sqlstring readme for more explanation:
|
also https://stackoverflow.com/questions/51673896/load-data-infile-and-spatial-data might be helpful |
When I try to insert multiple rows with a bulk insert and use the execute() method I get the error:
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 '?' at line 1
It works, when I use the query() method.
This is the interesting part of my code:
Seems like the replacement of the ? on bulk inserts doesn't work properly with the execute() method.
The text was updated successfully, but these errors were encountered: