I'm getting an error with trying to use batchInsert with Knex (Postgres DB).
It works if I'm inserting like 150 rows perfectly fine, but I've tried increasing the size of rows to like 7000 and I get this error:
bind message has 2072 parameter
formats but 0 parameters
I'm assuming this has to do with the size of the data I'm trying to insert since this only happens when I increase the size to that amount, but I thought batchInsert was supposed to work for a large amount of columns being inserted. If not, is there a way to increase this size, or is there another way I need to insert that many rows?
Here is my batchInsert function:
async function create(req, res) {
//create new asset in the system
const chunkSize = 25000;
const date = new Date();
const result = !Array.isArray(req.body.data) ? { //stringify single asset history into json array
...req.body.data, history: JSON.stringify(req.body.data.history)
} : req.body.data.map(data => {return {...data, history: JSON.stringify(data.history), updated_at: JSON.stringify(date)}}); //stringify each bulk asset's history into json array
const data = await knex
// .insert(result)
.batchInsert('assets', result, chunkSize)
.returning("*")
.then((results) => results[0]); //return result
res.status(201).json({ data });
}
I've randomly set this chunk size, but is there an actual specific number I need to set this too?
Any insight here would be greatly appreciated.
Thank you.