How to add comma separated values from text component to query's "IN"

I have a text component where users can enter order ids separated by commas:

e.g.

125,126,129

Then in a query, I want to make a where clause where I use it in clause “IN”.

I’ve tried this:

WHERE         
 (true = {{ order_ids.value == "" }} OR orders.id IN ({{ order_ids.value.split(',').map(i => parseInt(i)) }}))

I was assuming I need to convert it to an array first and then convert each one to the integer.

But this doesn’t work. The orders.id is an integer in DB.

The error I’m getting:

invalid input syntax for integer: "{NULL}"

Hey @ckissi! Your current code for that split operation is going to output an array, which isn’t going to work here - you’ll need to use the ANY keyword:

OR orders.id = ANY({{ order_ids.value.split(',').map(i => parseInt(i)) }})
1 Like