# How to send MQTT string value to a postgres table

**URL:** <https://discourse.nodered.org/t/how-to-send-mqtt-string-value-to-a-postgres-table/77757>\
**Category:** General\
**Tags:** database, function-node, mqtt\
**Created:** [20 April 2023 23:19 UTC](https://discourse.nodered.org/t/how-to-send-mqtt-string-value-to-a-postgres-table/77757 "2023-04-20T23:19:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![daaven](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@daaven](https://discourse.nodered.org/u/daaven)\
**Post date:** [20 April 2023 23:19 UTC](https://discourse.nodered.org/t/how-to-send-mqtt-string-value-to-a-postgres-table/77757/1 "2023-04-20T23:19:57Z")

</div>

![Screenshot (27)](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/851e38f71aec7ca1b3860bb2c5901dea776f970d.png)  
 ![Screenshot (29)](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/9/e928362abdca805b6982c303f06696c279a0b714.png)

I have an MQTT node called "description" this node comes in as ASCII code from a PLC. The string node converts the ASCII code into a string value. I inserted debugs node so you can see how the message is moving. My function node has:

var query1 = "INSERT INTO testing (tech\_name) VALUES ('" + msg.payload + "')";  
msg.topic = "sql";  
msg.payload = query1;  
return msg;

I inserted a picture of the table I have in postgres and the data type the columns use. "tech\_name" uses data type 'text' which should accept string values. I keep getting the error "error: invalid message format" even though I am using a string value

---

<div class="post-metadata">

**Author:** ![daaven](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@daaven](https://discourse.nodered.org/u/daaven)\
**Post date:** [20 April 2023 23:20 UTC](https://discourse.nodered.org/t/how-to-send-mqtt-string-value-to-a-postgres-table/77757/2 "2023-04-20T23:20:46Z")

</div>

[flows (2).json](https://discourse.nodered.org/uploads/short-url/88Hx00P6vwFss8smimiJAZpV3W8.json) (3.7 KB)

That is the flow I am using

---

<div class="post-metadata">

**Author:** ![Bean](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bean/32/78987_2.png) [@Bean](https://discourse.nodered.org/u/Bean)\
**Post date:** [20 April 2023 23:45 UTC](https://discourse.nodered.org/t/how-to-send-mqtt-string-value-to-a-postgres-table/77757/4 "2023-04-20T23:45:40Z")

</div>

> error: invalid message format

This means that the msg being sent to that node is not right.  
Take at look [here](https://flows.nodered.org/node/node-red-contrib-postgresql) and [here](https://github.com/unirobot/node-red-contrib-postgres) to check the proper way to contruct the message to send to the postgres node.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [19 June 2023 23:45 UTC](https://discourse.nodered.org/t/how-to-send-mqtt-string-value-to-a-postgres-table/77757/5 "2023-06-19T23:45:47Z")

</div>

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