Postgres node is not working with IN Operator when the parameters is an Array. I suppose that’s because of the sanity checks.
E.g. I have a list of some workflows that I’m returning via the n8n API. Then I want to get all executions for each of them (I do not want to do it via the n8n API as it doesn’t provide a filtering functionality by date). So the fixed query would be like that:
SELECT
finished,
status,
"startedAt",
"stoppedAt",
"workflowId",
workflow_entity.name AS "workflowName"
FROM execution_entity, workflow_entity
WHERE "workflowId" = workflow_entity.id AND "startedAt"::date >= current_date-1 AND "startedAt"::date < current_date AND "workflowId" IN ('wfId1', 'WfId2')
But I haven’t found a way to do so with parameters. I’ve used couple of options. As an Array (Only the executions of the first workflowId has been returned)
As a query part (no success, seems the node just enclosed it into a string):
Hi @barn4k, I’m not an expert on Postgres or the node itself, so I’m just guessing here but maybe you could try turning the array of workflowIds into a string of comma separated workflowIds in the Query Parameters expressions? So something like this:
Sorry @barn4k , for some reason the formatting got changed in the expression when I pasted earlier. Could you try adding backticks around the double quoted expression to create template literals like this:
You could also dynamically construct the array of placeholders like ($1, $2, $3) using an expression. This is a MySQL example but it should be the same for Postgres:
Query parameters are an extra layer of security to prevent SQL injection attacks. If you can trust the data you’re inserting into your SQL, then you don’t need them.
If you’d like help debugging your error, please post your workflow. Thanks!
Hey! I just came across the same issue. Turns out, you don’t need to use join(‘,’) on the query parameters.
Just use {{ $json.array }} and it should work!
I think n8n treats {{ $json.array.join(‘,’) }} as a string, not as an array.