I have a text input component for users to enter ids that are separated by commas and the ids are used as a filtering condition in the query. For example, the user may enter 123, 456 while the text component value becomes "123, 456".
I have tried the method = ANY({{ IDsFilter.value.split(', ').map(i => parseInt(i)) }} but it doesn't work. I am using Snowflake db.
You might want to be using: WHERE SEQUENCE_ID IN FLATTEN({{ IDsFilter.value.split(', ').map(i => parseInt(i)) }}). This should look like "...IN FLATTEN(123, 456)" for it to make it work.
I work with BigQuery mostly so had to check the "UNNEST" equivalent in Snowflake. Not sure if that works but what you want to aim is having this look in your 'WHERE' statement: WHERE id IN (123, 456, 78, 90). I would use a transformer for this, returning an array of those ids. Then in your snowflake query, I would FLATTEN(transformer.value).
SQL can filter using an array like condition. if you want to filter out, just add NOT before IN.
Thank you so much for the feedback. Using a transformer is good advice because I need to use the flatten ID in more than one place.
I could flatten the ids string into the individual numbers using SPLIT_TO_TABLE function. In the screenshot example, the transformer outputted two ID values. However, when I used the transformer output {{IDs.data.VALUE}} in the WHERE clause in another query, it only returned one ID's data. Not sure why it happens.
Thank you so much for getting back to me!
Not sure why the solution is not working for my case. But based on your suggestion and the documentation you shared earlier, I found the below solution works.
select
*
from
table
where
{{ textinput.value }} like '%' || table.id || '%'