Query parameters not working with Postgres

Describe the issue/error/question

I’m new to N8N and it is looking promising. I’m trying to get a postgres query working with some variables. like select * from tenant where tenant is $1;
in the query parameters I pass in a value, but I never get any result (always empty)
if I hardcode the the tenant to a value in the query it is working, only not if I specify this via the query parameters.

What is the error message (if any)?

no errors, just no data

Please share the workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database you’re using (default: SQLite):
  • Running n8n with the execution process [own(default), main]:
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: I’m running desktop app

Hi @Edward, welcome to the community! n8n would populate the query parameters using incoming data. So the Query Parameters field expects the name of one (or more) incoming fields like so:

Workflow:

In this example using a parameter wouldn’t make much sense, but it becomes more useful if you need to run queries for more than one incoming item :slight_smile:

Hope this makes sense and helps!

2 Likes

oef, so simple… :grinning:

I was using an expression to get the value, but that seems not to work. although the expression editor was showing the correct result.
Does this mean that for postgres you only should use the input fields directly and not via expressions?

You can use expressions if you like, but I wouldn’t recommend it as it is a possible SQL injection vector. To use expressions, you would need to add them directly in the Query field rather than through parameters:

Recording 2022-08-31 at 08.31.59

So instead you might want to consider first using a Set node for your expressions, and only then use query parameters in the Postgres node itself.

Thanks for the quick answers! using a set is what I did now.
working perfectly!
Thanks for your help.

1 Like

You are most welcome, thanks so much for confirming!