# How to Insert Bool Values to PostgreSQL over Node Red

**URL:** <https://discourse.nodered.org/t/how-to-insert-bool-values-to-postgresql-over-node-red/67949>\
**Category:** General\
**Tags:** database\
**Created:** [19 September 2022 22:05 UTC](https://discourse.nodered.org/t/how-to-insert-bool-values-to-postgresql-over-node-red/67949 "2022-09-19T22:05:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Comrade](https://avatars.discourse-cdn.com/v4/letter/c/2bfe46/32.png) [@Comrade](https://discourse.nodered.org/u/Comrade)\
**Post date:** [19 September 2022 22:05 UTC](https://discourse.nodered.org/t/how-to-insert-bool-values-to-postgresql-over-node-red/67949/1 "2022-09-19T22:05:52Z")

</div>

Hello. I'm a beginner with Node-Red, I try to insert bollean data to PostgreSQL.  
For example, I have 4 boolean variables and I need insert this to PostgreSQL table.

 ![table](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/3/73871ae736278a91928c4c84c88a220fe34936e2.png)  
My flow is^  
 ![777](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/046720044459deceae0a3ca11eac8e23c169fd3e.png)

I get an error:  
"error: invalid syntax for type boolean: """

If I use only payload all is work.

```auto
INSERT INTO corp36_pump1(tstamp, on_off, local, disable, alarm)
VALUES (NOW(), '{{msg.payload.on_off}}', true, true, true);

```

Sorry, this is probably a stupid question. What is correct syntax?

Maybe someone could help me to solve it?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [19 September 2022 23:42 UTC](https://discourse.nodered.org/t/how-to-insert-bool-values-to-postgresql-over-node-red/67949/2 "2022-09-19T23:42:25Z")

</div>

Welcome Comrade!

Each message which arrives at a node is manipulated by the node **without any knowledge of previous messages**. (There are some exceptions but I don't think the Postgres node is one.)

Each one of the outputs from your "Word to bits" node is a discrete message.  
They are each modified by a change node and then they arrive at the "Corp\_36 Status" node **seperately**.

But you are expecting "Corp\_36 Status" to handle 4 messages as if they were one.  
This is not the way it works. Instead it produces 4 SQL statements something like

```auto
INSERT INTO corp36_pump (tstamp, on_off, local, disable, alarm)
VALUES (NOW(), "", true, "", "");

```

What you can do is:  
In your change nodes, set a different msg.topic for each message.  
Then use a join node (in Manual mode) to join them into a single message.  
Put a debug node after the join so you can see the structure of the newly joined message.

---

<div class="post-metadata">

**Author:** ![Comrade](https://avatars.discourse-cdn.com/v4/letter/c/2bfe46/32.png) [@Comrade](https://discourse.nodered.org/u/Comrade)\
**Post date:** [21 September 2022 05:46 UTC](https://discourse.nodered.org/t/how-to-insert-bool-values-to-postgresql-over-node-red/67949/3 "2022-09-21T05:46:16Z")

</div>

Hello, jbudd!  
Thank you very much, your solution is works!  
I tested it, all is work. In this wariant will 4 reqest to Postges.

Maybe it will be useful for someone:  
changed nodes to convert to single query string (code below)  
[sql\_flows.json](https://discourse.nodered.org/uploads/short-url/yvVpJpNyAn46b5orixUqAa2ndoP.json) (11.4 KB)

jbudd, thanks for your help, I couldn't have done it without you.

---

<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:** [20 November 2022 05:47 UTC](https://discourse.nodered.org/t/how-to-insert-bool-values-to-postgresql-over-node-red/67949/4 "2022-11-20T05:47:12Z")

</div>

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