# Node-red-contrib-postgresql 0.9.0 with global variables

**URL:** <https://discourse.nodered.org/t/node-red-contrib-postgresql-0-9-0-with-global-variables/60648>\
**Category:** General\
**Tags:** database\
**Created:** [1 April 2022 12:26 UTC](https://discourse.nodered.org/t/node-red-contrib-postgresql-0-9-0-with-global-variables/60648 "2022-04-01T12:26:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![luis.brito](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@luis.brito](https://discourse.nodered.org/u/luis.brito)\
**Post date:** [1 April 2022 12:26 UTC](https://discourse.nodered.org/t/node-red-contrib-postgresql-0-9-0-with-global-variables/60648/1 "2022-04-01T12:26:10Z")

</div>

Hi,

I'm using "node-red-contrib-postgresql 0.9.0" to change data with a PostgresSQL database.

To use variables in my query it's necessary to use {{{msg.payload.VARIABLE}}}, and it's working fine. But when i tried to use {{{global.get("VARIABLE")}}} this not work.

Can anyone help me telling the right syntax to use global variables in my case?

Thanks.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 April 2022 13:35 UTC](https://discourse.nodered.org/t/node-red-contrib-postgresql-0-9-0-with-global-variables/60648/2 "2022-04-01T13:35:36Z")

</div>

Have you tried `{{{global.VARIABLE}}}`

---

<div class="post-metadata">

**Author:** ![luis.brito](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@luis.brito](https://discourse.nodered.org/u/luis.brito)\
**Post date:** [1 April 2022 14:38 UTC](https://discourse.nodered.org/t/node-red-contrib-postgresql-0-9-0-with-global-variables/60648/3 "2022-04-01T14:38:09Z")

</div>

Thanks for the answer!

I tested it and, does not work yet.

I have tried:

-{{{global.VARIABLE}}}  
-{{{global."VARIABLE"}}}  
-{{{global.get("VARIABLE")}}}

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 April 2022 14:49 UTC](https://discourse.nodered.org/t/node-red-contrib-postgresql-0-9-0-with-global-variables/60648/4 "2022-04-01T14:49:21Z")

</div>

Exactly where are you entering that?

Also what do you mean by does not work?

---

<div class="post-metadata">

**Author:** ![luis.brito](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@luis.brito](https://discourse.nodered.org/u/luis.brito)\
**Post date:** [1 April 2022 15:13 UTC](https://discourse.nodered.org/t/node-red-contrib-postgresql-0-9-0-with-global-variables/60648/5 "2022-04-01T15:13:43Z")

</div>

In my case, i need to read the column "modelo\_turno" from the table "usuario".

The query camp is working like that:

SELECT modelo\_turno  
FROM {{{msg.payload.schema}}}.usuario

The schema will be a string variable, because of that i am using a function node before the PostgresSQL node to read a string from a global variable and write it on the msg.payload to use in my query.

Would simplify my program if i use the global variable directly, instead of using the function all time.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 April 2022 15:52 UTC](https://discourse.nodered.org/t/node-red-contrib-postgresql-0-9-0-with-global-variables/60648/6 "2022-04-01T15:52:14Z")

</div>

> [@luis.brito](#):
>
> i am using a function node

So what exactly isn't working?

---

<div class="post-metadata">

**Author:** ![luis.brito](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@luis.brito](https://discourse.nodered.org/u/luis.brito)\
**Post date:** [1 April 2022 16:24 UTC](https://discourse.nodered.org/t/node-red-contrib-postgresql-0-9-0-with-global-variables/60648/7 "2022-04-01T16:24:17Z")

</div>

Everything is working, but i want to know if its possible to use the global variable instead of the msg.payload in my query.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 April 2022 18:14 UTC](https://discourse.nodered.org/t/node-red-contrib-postgresql-0-9-0-with-global-variables/60648/8 "2022-04-01T18:14:54Z")

</div>

> [@luis.brito](#):
>
> but i want to know if its possible to use the global variable instead of the msg.payload in my query.

In what way. In what node (full name e.g. node-red-contrib-xxxx)?

Can you show us how you are attempting to use this format?

---

<div class="post-metadata">

**Author:** ![luis.brito](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@luis.brito](https://discourse.nodered.org/u/luis.brito)\
**Post date:** [1 April 2022 18:34 UTC](https://discourse.nodered.org/t/node-red-contrib-postgresql-0-9-0-with-global-variables/60648/9 "2022-04-01T18:34:04Z")

</div>

I'm using Node-red-contrib-postgresql 0.9.0.

 ![Capturar](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f6f88bb2e3e1fe3cc7dff52d88d9025ead580d6a.jpeg)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 April 2022 19:19 UTC](https://discourse.nodered.org/t/node-red-contrib-postgresql-0-9-0-with-global-variables/60648/10 "2022-04-01T19:19:53Z")

</div>

> [@luis.brito](#):
>
> Node-red-contrib-postgresql 0.9.0

It seems the author has elected to only support the `msg` object (see here: [node-red-contrib-postgresql/postgresql.js at a524c9a77cd6481e6090d0dfee138c43509df574 · alexandrainst/node-red-contrib-postgresql · GitHub](https://github.com/alexandrainst/node-red-contrib-postgresql/blob/a524c9a77cd6481e6090d0dfee138c43509df574/postgresql.js#L166))

as opposed to the built in template node which supports `global` and `flow` context ([node-red/packages/node\_modules/@node-red/nodes/core/function/80-template.js at 702545e0b238f160cce9b339808b230f9d741b08 · Steve-Mcl/node-red · GitHub](https://github.com/Steve-Mcl/node-red/blob/702545e0b238f160cce9b339808b230f9d741b08/packages/node_modules/%40node-red/nodes/core/function/80-template.js#L183))

You could raise a request on the issues page of that node asking if the author would support accessing `{{{flow.var}}}` and `{{{global.var}}}` in the node.

That said, you are far better off using parameters (as described here: [GitHub - alexandrainst/node-red-contrib-postgresql: Node-RED node for PostgreSQL, supporting parameters, split, back-pressure](https://github.com/alexandrainst/node-red-contrib-postgresql#named-parameterized-query)) as they will help you avoid the problem of quotes in string values and avoid SQL injection issues.

---

<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:** [31 May 2022 19:20 UTC](https://discourse.nodered.org/t/node-red-contrib-postgresql-0-9-0-with-global-variables/60648/11 "2022-05-31T19:20:06Z")

</div>

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