i'm trying to pump a JSON array into a MYSQL Database, i already found something similiar but the Solution is not working for me. Similiar issue i found
Here is my try of first stringify the body from the Request and after that push that via
INSERT INTO table SET ?
Table is created like:
CREATE TABLE IF NOT EXISTS db.AStockHistory
( Symbol text NOT NULL,
Date timestamp NOT NULL,
Open double,
High double,
Low double,
Close double,
Volume double,
Dividends double,
Stock_Splits double );
my Code from NodeJS:
async function create(stockHistory){
var data = JSON.stringify(stockHistory);
const result = await db.query(
`INSERT INTO db.AStockHistory SET ?`, data);
return {message};
}
Here is my full JSON array i try to push via postman. The gereated structure of the JSON is made by a pandas dataframe.
[
{
Symbol: 'msft',
Date: '2022-07-20 00:00:00',
Open: 259.8999938965,
High: 264.8699951172,
Low: 258.9100036621,
Close: 262.2699890137,
Volume: 22788300,
Dividends: 0,
Stock_Splits: 0
},
{
Symbol: 'msft',
Date: '2022-07-21 00:00:00',
Open: 259.7900085449,
High: 264.8900146484,
Low: 257.0299987793,
Close: 264.8399963379,
Volume: 22404700,
Dividends: 0,
Stock_Splits: 0
},
{
Symbol: 'msft',
Date: '2022-07-22 00:00:00',
Open: 265.2399902344,
High: 265.3299865723,
Low: 259.0700073242,
Close: 260.3599853516,
Volume: 21871000,
Dividends: 0,
Stock_Splits: 0
},
{
Symbol: 'msft',
Date: '2022-07-25 00:00:00',
Open: 261,
High: 261.5,
Low: 256.8099975586,
Close: 258.8299865723,
Volume: 21056000,
Dividends: 0,
Stock_Splits: 0
},
{
Symbol: 'msft',
Date: '2022-07-26 00:00:00',
Open: 259.8599853516,
High: 259.8800048828,
Low: 249.5700073242,
Close: 251.8999938965,
Volume: 38096200,
Dividends: 0,
Stock_Splits: 0
}
]
I'm getting the following Output:
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 ''[{"Symbol":"msft","Date":"2022-07-20 00:00:00","Open":259.8999938965,' at line 1 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 ''[{"Symbol":"msft","Date":"2022-07-20 00:00:00","Open":259.8999938965,' at line 1 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 ''[{"Symbol":"msft","Date":"2022-07-20 00:00:00","Open":259.8999938965,' at line 1 at PromiseConnection.query
db.query(`INSERT INTO db.AStockHistory VALUES (?)`, data);
?