I'm trying to import a considerable amount of XML data into a TimescaleDB in Postgresql. I'm using the node-red-contrib-postgresql node. I've got it to the point where the data has the correct columns assigned to it, but I've been banging my head against the wall trying to get the msg.params setup properly to get it into the database.
Without the function trying to define msg.params, I predictably get the params not being defined:
error: there is no parameter $1 INSERT INTO power_data (time, value, production_type) VALUES ($1, $2, $3);
With this function defined:
// Initialize an array to store the flattened message parameters
msg.params = [];
// Iterate over each entry in the payload array
msg.payload.forEach(function(entry) {
// Extract timestamp, value, and production type from the entry
var time = entry.time;
var value = entry.value;
var productionType = entry.production_type;
// Construct an array of parameters for the current row
var rowParams = [time, value, productionType];
// Push the parameters of the current row to the flattened message parameters array
msg.params.push(rowParams);
});
// Log the message parameters array for debugging
console.log("Message parameters: ", msg.params);
// Return the message
return msg;
I get the following error:
error: bind message supplies 6192 parameters, but prepared statement "" requires 3 INSERT INTO power_data (time, value, production_type) VALUES ($1, $2, $3);
I am VERY new to this, so please go easy!