Node-red-contrib-postgresql 0.9.0 with global variables


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?


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

Thanks for the answer!

I tested it and, does not work yet.

I have tried:


Exactly where are you entering that?

Also what do you mean by does not work?

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.

So what exactly isn't working?

Everything is working, 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?

I'm using 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)

as opposed to the built in template node which supports global and flow context (node-red/80-template.js at 702545e0b238f160cce9b339808b230f9d741b08 · Steve-Mcl/node-red · GitHub)

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) as they will help you avoid the problem of quotes in string values and avoid SQL injection issues.

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