Passing integer values using additionalScope to SQL IN clause

Hi,

Need to pass a comma separated list of integers to a query using additionalScope, is this possible?

Here's the setup:

query1:

select * from table_name where id in ( {{ _ids }} )

Javascript code:

query1.trigger({additionalScope: { _ids: [1,2] } });

Passing comma separated _ids ("1,2") in additionalScope and triggering the query gives the following error:

invalid input syntax for integer: "1,2"

Passing an array for _ids ([1,2]) in additionalScope and triggering the query gives the following error:

invalid input syntax for integer: "{"1","2"}"

Is there a way to pass a list of integers in additionalScope so that it can be used for a SQL query's IN clause? Or will I need to use a for loop in Javascript?

Hey Anand!

You should definitely be able to trigger that query with additionalScope. The syntax with an array there is a little bit different. This should work for you.

  1. Create the array of ids and pass it in as additionalScope:
    Screenshot 2023-06-08 at 2.51.14 PM

  2. Accept the additionalScope variable in the SQL query using the ANY operator

This should give you the results you are looking for!

As a side note, this syntax is specific to Postgres. If you are using a different SQL resource, let us know and we can help modify that query accordingly.

2 Likes

Hey Joe!

Thank you so much, your solution worked like a charm!

Regards,
Anand

1 Like