# Node-Red to PostgreSQL

**URL:** <https://discourse.nodered.org/t/node-red-to-postgresql/75926>\
**Category:** General\
**Tags:** database\
**Created:** [1 March 2023 10:19 UTC](https://discourse.nodered.org/t/node-red-to-postgresql/75926 "2023-03-01T10:19:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chrolloo123](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chrolloo123/32/76945_2.png) [@Chrolloo123](https://discourse.nodered.org/u/Chrolloo123)\
**Post date:** [1 March 2023 10:19 UTC](https://discourse.nodered.org/t/node-red-to-postgresql/75926/1 "2023-03-01T10:19:15Z")

</div>

I just recently used Node-red. I created a function that can save to local postgres using node-red-contrib-postgres-multi package

I have a data from my mqtt client:

```auto
    msg.topic = 'data'
    msg.payload = [
            { key: 'pumpingstation', value: '0.00' },
            { key: 'centrifuge', value: '21.08' },
            { key: 'Dafpump1', value: '5.20' },
            { key: 'Dafpump2', value: '23.10' }
          ]

```

in my function node it look like this:

```auto
    var topic1 = msg.topic;
    var payload1 = msg.payload;
    
    msg.payload = [
        {
            query: 'INSERT INTO mqtt_table (topic, payload) values (1, $topic), (2, $payload)',
            params: {
                topic: topic1,
                payload: payload1,
            },
        },
        {
            query: 'commit',
        },
    ];
    // Return the modified message
    return msg;

```

and in my postgres node I have set up my credentials correctly. There's no error but it's not saving to my database. Is there something wrong with my process? Let me know if my question is not clear. Thanks!

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/76cb8b48ab3a32cb9b6b78ff2e95486e447fd317.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/945be7e32de33078aee626f0e4d44d618aa8431c.png)

---

<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:** [1 March 2023 10:21 UTC](https://discourse.nodered.org/t/node-red-to-postgresql/75926/2 "2023-03-01T10:21:24Z")

</div>

add a `debug` node (set to display the complete msg object) to the output of the `Postgres` node and also add a `catch` node connected to another `debug` node (set to display the complete msg object) and see what shows up.

---

<div class="post-metadata">

**Author:** ![Chrolloo123](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chrolloo123/32/76945_2.png) [@Chrolloo123](https://discourse.nodered.org/u/Chrolloo123)\
**Post date:** [1 March 2023 10:30 UTC](https://discourse.nodered.org/t/node-red-to-postgresql/75926/3 "2023-03-01T10:30:31Z")

</div>

on function 3 it shows

```auto
[
  {
    query: 'INSERT INTO mqtt_table (topic, payload) values (1, $topic), (2, $payload)',
    params: {
      topic: 'data',
      payload: [
        { key: 'pumpingstation', value: '1.00' },
        { key: 'centrifuge', value: '21.08' },
        { key: 'Dafpump1', value: '5.20' },
        { key: 'Dafpump2', value: '23.10' }
      ]
    }
  },
  { query: 'commit' }
]

```

there's no debug output on postgres node.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/b/ebbf7c058ba7a3212b5f70b2a4f2cea6cac7962e.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/55de5b256a88792ae55044e79e2694f22f4661b1.png)

---

<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:** [1 March 2023 11:33 UTC](https://discourse.nodered.org/t/node-red-to-postgresql/75926/4 "2023-03-01T11:33:37Z")

</div>

what it the full name of the postgres node you are using?

---

<div class="post-metadata">

**Author:** ![Chrolloo123](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chrolloo123/32/76945_2.png) [@Chrolloo123](https://discourse.nodered.org/u/Chrolloo123)\
**Post date:** [1 March 2023 11:36 UTC](https://discourse.nodered.org/t/node-red-to-postgresql/75926/5 "2023-03-01T11:36:49Z")

</div>

node-red-contrib-postgres-multi

---

<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:** [1 March 2023 11:40 UTC](https://discourse.nodered.org/t/node-red-to-postgresql/75926/6 "2023-03-01T11:40:22Z")

</div>

That node hasn't been updated in over 5 years and if you go to the [GitHub page and look at the issues](https://github.com/BruceFletcher/node-red-contrib-postgres-multi/issues) it looks like it is broken

I would try another node.

---

<div class="post-metadata">

**Author:** ![Chrolloo123](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chrolloo123/32/76945_2.png) [@Chrolloo123](https://discourse.nodered.org/u/Chrolloo123)\
**Post date:** [1 March 2023 11:41 UTC](https://discourse.nodered.org/t/node-red-to-postgresql/75926/7 "2023-03-01T11:41:02Z")

</div>

can you recommend a node for postgres?

---

<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:** [1 March 2023 11:45 UTC](https://discourse.nodered.org/t/node-red-to-postgresql/75926/8 "2023-03-01T11:45:28Z")

</div>

Since I don't use Postgres I can't give an opinion. I would suggest you

1. do a search on the forum using `Postgres` and look at what others are using
2. go to the ~Flow`tab on the forum, search for`Postgres` and go to the GitHub pages for the nodes and look at the issues for each node.

That should help you decide.

---

<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:** [30 April 2023 11:46 UTC](https://discourse.nodered.org/t/node-red-to-postgresql/75926/9 "2023-04-30T11:46:18Z")

</div>

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