Hi all,
I have the following scenario:
Database A has a table along with several timestamp columns
Database B has the exact same schema for that table
I want to read rows from A and insert them in B.
Sounds easy?
Thats what I read from DB A:
{"ts":"2020-04-23T05:15:29.782Z","country":"testcountry","city":"testcity","line":"A03","packageid":"e9a0abbe-2a92-4947-a635-fe05709777e8","boxid":"12345","configname":"Gen2_BC","module":"LineController","event":"Induct"}
And that is what JS/Node-Red creates:
INSERT INTO boxes (ts,country,city,line,packageid,boxid,configname,module,event) VALUES ('Thu Apr 23 2020 05:15:29 GMT+0000 (Coordinated Universal Time)','testcountry','testcity','A03','e9a0abbe-2a92-4947-a635-fe05709777e8','12345','Gen2_BC','LineController','Induct');
Why the hell is the timestamp column modified? I just want to insert the exact same string "ts" as I get it from DB A. So, something parses the ts column and modifies it to a human readable format. And I find no way to avoid that....
Thats the code I use:
sqlCommands = [];
sqlCommands.push({ "query" : "BEGIN;" });
for (i=0; i< msg.payload.length; i++)
{
let row = msg.payload[i];
let names= Object.keys(row).join(',');
let values= Object.values(row).join("','");
sqlCommand = "INSERT INTO boxes (" + names + ") VALUES ('" + values + "');";
sqlCommands.push({ "query" : sqlCommand });
}
sqlCommands.push({ "query" : "COMMIT;" });
msg.payload= sqlCommands;
msg.rows = msg.payload.length;
return msg;
Any ideas? And I don't want to manually create the statement as I don't know if someone adds mor columns etc.
Thanks!
Version:
Node-Red 1.0.1
node-red-contrib-postgres-multi 0.2.0