SQL Parameter 'IN' Operator

What is the correct syntax for specifying a list of values as a parameter in a SQL query?

SELECT a FROM b WHERE a IN
{{pet_list}}
– [‘dog’, ‘cat’, ‘chinchilla’]

Thank you!

Hi,
what do you want to achive? do you want to pre-select certain filter variables (that is not possible right now). see topic: Filter variables can´t be pre-selected

or do you want to preselect certain values in your query (without using a filter)? then the correct syntax would be:
(assuming that pet_list is your field you want to filter at?)

WHERE pet_list IN (“dog”, “cat”, “chinchilla”)

Hope that helps.
Cheers, Eva

1 Like

Hello,

I have the same problem.
How can we deal with the IN operator and a field filter ?

Regards

@Nonow53 What do you mean about “deal with the IN”? Metabase takes care of that for you, when using Field Filters:
https://www.metabase.com/docs/latest/users-guide/13-sql-parameters.html#the-field-filter-variable-type

Yes, I have found the solution.
I added only the field filter name in my SQL request and it works (I had to put an IN clause).
It would be better documented :slight_smile:

Thanks

@Nonow53 You’re more than welcome to suggest changes to the documentation:
https://www.metabase.com/docs/latest/users-guide/13-sql-parameters.html#see-something-that-needs-fixing-propose-a-change-on-the-source