Hello,
I want to convert msg.payload Value into an array for sql database. Attached debug message screenshot.
Thanks in advance.
Br,
Devendra
Hello,
I want to convert msg.payload Value into an array for sql database. Attached debug message screenshot.
Thanks in advance.
Br,
Devendra
What type of database? (SQL server 20xx? Mysql? Sqlite?)
What node are you using? (Full name please e.g. node-red-contrib-xxxxx)
Hi,
I am using PostgresSQL database.
Node - node-red-contrib-postgres-multi.
Br,
Devendra
According to the readme you need to format the payload in a particular way.
Try adding a function node and put this code in (you will need to modify the SQL)...
msg.payload = [
{
query: 'insert into mytable (message) values (1, $p1)',
params: {
p1: msg.payload
},
},
];
return msg;
Hello,
I tried same but not working.
Below is my Write SQL query program. which i have done in function node.
msg.payload value is unsigned8 bit (ex. 13 or 234 etc).
var timestamp = new Date().getTime();
var name = "Sensor1"
var value = msg.payload;
if (flow.get("Start")===true){
msg.payload = "INSERT INTO table1 VALUES("+timestamp+","+name+","+value+")";
return msg;
}
Br,
Devendra
↑ That is nothing like the correct format. Did you read my post or open the "readme"?
This should get you closer to a solution...
var timestamp = new Date().getTime();
var name = "Sensor1"
var value = msg.payload;
msg.payload = [
{ query:`INSERT INTO table1 VALUES(${timestamp},'${name}',${value})` }
];
return msg;
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.