# Mysql, mariadb INSERT fail - "msg.payload should be an object containing the query arguments."

**URL:** <https://discourse.nodered.org/t/mysql-mariadb-insert-fail-msg-payload-should-be-an-object-containing-the-query-arguments/29905>\
**Category:** General\
**Created:** [11 July 2020 17:32 UTC](https://discourse.nodered.org/t/mysql-mariadb-insert-fail-msg-payload-should-be-an-object-containing-the-query-arguments/29905 "2020-07-11T17:32:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adao\_Branco](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/adao_branco/32/25591_2.png) [@Adao\_Branco](https://discourse.nodered.org/u/Adao_Branco)\
**Post date:** [11 July 2020 17:32 UTC](https://discourse.nodered.org/t/mysql-mariadb-insert-fail-msg-payload-should-be-an-object-containing-the-query-arguments/29905/1 "2020-07-11T17:32:38Z")

</div>

I try insert data do mysql, but give this error : "msg.payload should be an object containing the query arguments."  
If I inject manual ; INSERT INTO consumo ( data, hora, voltagem, corrente, potencia, pf, kwh ) VALUES ('2020-07-11', '17:59:13', 235.3, 1.42, 292.0, 0.87, 180061) - works good

11/07/2020, 17:59:12[node: 645b9468.b3369c](http://192.168.1.185:1880/#)white21\_pzem004\_fixo : msg : Object  
_object_  
topic: "white21\_pzem004\_fixo"  
payload: "INSERT INTO consumo ( data, hora, voltagem, corrente, potencia, pf, kwh ) VALUES ('2020-07-11', '17:59:13', 235.3, 1.42, 292.0, 0.87, 180061)"  
qos: 0  
retain: false  
\_topic: "white21\_pzem004\_fixo"  
\_msgid: "e22112b1.1c175"

11/07/2020, 17:59:12[node: c4c94992.70def8](http://192.168.1.185:1880/#)msg : string[63]  
"msg.payload should be an object containing the query arguments."

11/07/2020, 17:59:12[node: 9df8fbb.7d5b708](http://192.168.1.185:1880/#)INSERT INTO consumo ( data, hora, voltagem, corrente, potencia, pf, kwh ) VALUES ('2020-07-11', '17:59:13', 235.3, 1.42, 292.0, 0.87, 180061) : msg : Object  
_object_  
topic: "INSERT INTO consumo ( data, hora, voltagem, corrente, potencia, pf, kwh ) VALUES ('2020-07-11', '17:59:13', 235.3, 1.42, 292.0, 0.87, 180061)"  
qos: 0  
retain: false  
\_topic: "white21\_pzem004\_fixo"  
\_msgid: "e22112b1.1c175"

Flow:

```auto
[{"id":"e71cac20.dd98f","type":"Stackhero-MySQL","z":"23f837d8.44d508","server":"59f71098.17a99","name":"","x":690,"y":180,"wires":[[]]},{"id":"903152e1.51393","type":"debug","z":"23f837d8.44d508","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":670,"y":240,"wires":[]},{"id":"73571c09.825bd4","type":"mqtt in","z":"23f837d8.44d508","name":"","topic":"white21_pzem004_fixo","qos":"0","datatype":"auto","broker":"a1dff73d.4ba558","x":160,"y":100,"wires":[["6556610c.fb663","3fc9fa54.514e96"]]},{"id":"6556610c.fb663","type":"debug","z":"23f837d8.44d508","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":500,"y":100,"wires":[]},{"id":"3fc9fa54.514e96","type":"change","z":"23f837d8.44d508","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":220,"wires":[["e71cac20.dd98f","903152e1.51393"]]},{"id":"59f71098.17a99","type":"Stackhero-MySQL-Server","z":"","name":"","host":"127.0.0.1","port":"3306","tls":false,"database":"pzem_movel"},{"id":"a1dff73d.4ba558","type":"mqtt-broker","z":"","name":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

What I'm doing wrong, can someone help.  
Thanks.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 July 2020 18:33 UTC](https://discourse.nodered.org/t/mysql-mariadb-insert-fail-msg-payload-should-be-an-object-containing-the-query-arguments/29905/2 "2020-07-11T18:33:25Z")

</div>

Put a `debug` node (set to display the complete msg.object) on the output of your `mqtt-in` node.  
You could also try changing the `change` node to `set' msg.topic to msg.payload

The move - in the `change` node does that, it moves msg.payload to msg.topic so msg.payload no longer exists. Maybe ther node can't handle msg.payload being empty.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 July 2020 18:38 UTC](https://discourse.nodered.org/t/mysql-mariadb-insert-fail-msg-payload-should-be-an-object-containing-the-query-arguments/29905/3 "2020-07-11T18:38:19Z")

</div>

UPDATE: I just tested and if msg.payload is empty, the node throws an error - I'll open an issue on the node.

so changing the `change` node should fix the error

Issue on GitHub: [https://github.com/stackhero-io/node-red-contrib-stackhero-mysql/issues/1](https://github.com/stackhero-io/node-red-contrib-stackhero-mysql/issues/1)

---

<div class="post-metadata">

**Author:** ![Adao\_Branco](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/adao_branco/32/25591_2.png) [@Adao\_Branco](https://discourse.nodered.org/u/Adao_Branco)\
**Post date:** [12 July 2020 08:28 UTC](https://discourse.nodered.org/t/mysql-mariadb-insert-fail-msg-payload-should-be-an-object-containing-the-query-arguments/29905/4 "2020-07-12T08:28:14Z")

</div>

Thanks for your help.  
I replaced Stackhero Mysql with mysql node and works fine.

---

<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:** [26 July 2020 08:28 UTC](https://discourse.nodered.org/t/mysql-mariadb-insert-fail-msg-payload-should-be-an-object-containing-the-query-arguments/29905/5 "2020-07-26T08:28:15Z")

</div>

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