Hello, I have a follow-up question related to a topic that has been discussed but is closed: Postgres use array as a query parameters
I want to pass an array into a Postgresql query as a query parameter. Ideally, I would create a query like this:
SELECT array_agg(id) AS ids
FROM business_case
WHERE status = 'done'
AND product_id = ANY($1)
And pass an array like this: [1,2,3,4]
(it comes from previous node like $json.id_array
. But this doesn’t work.
I know I can convert it with .join()
and use the IN
operator, but I want to understand how n8n works (and also wanted to use the ANY
operator.
I found a solution:
SELECT array_agg(id) AS ids
FROM business_case
WHERE status = 'done'
AND product_id = ANY(string_to_array($1, ',')::int[])
with query parameter: {{ $json.id_array.join() }}
.
Why my original query doesn’t work?
Thank you very much!
Honza