How to send MQTT node data (integers & string) to a table in postgres database

Node-RED version: v3.0.2
Node.js version: v18.12.1
I uploaded my flow chart, on the far left shows MQTT nodes. Customer Name and Description are both strings. Analog, Test Time, Test Pressure, Job Number, and Serial Number are all integer values. I can't seem to figure out what to insert in the function node to send to the database to place all the values in the same row when it uploads. I also uploaded a picture of the table I have in postgres. My current function node only uploads one integer value at a time and leaves of the rest of the columns blank.

Hi Daniel, welcome to the forum.

Can you show us your function node code please?

Basic understanding of node red should help.

Every node (I.e. all of your MQTT nodes) will output data at different times. Even if the MQTT messages are transmitted at the exact same time, messages travelling down the wires into the function node will never reach the function node at the same time.

In other words, you will only get one piece of information at a time. This can be clearly seen if you add a debug node before the function node.

See this article in the cookbook for an example of how to join messages into one object.

Once you have all of the values in a single message payload, you can easily build an SQL insert query with all of the values.

msg.topic = "INSERT INTO pressure_data (tech_name, pressure_value, job_num, serial_num, notes) VALUES ($1, $2, $3, $4, $5)";

msg.payload = [msg.payload[0], msg.payload[1], msg.payload[2], msg.payload[3], msg.payload[4]];

return msg;

That is the code currently in the function node. I have modified it, but still get no results

The help for the node-red-contrib-postgresql says to put values as an array in msg.params not msg.payload:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.