expr IN (value,...)
SELECT 2 IN (0,3,5,7);
0
SELECT 'wefwf' IN ('wee','wefwf','weg');
1
Returns 1 (true) if expr is equal to any of the values in the IN() list, else returns 0 (false).
SELECT 2 IN (0,3,5,7);
0
SELECT 'wefwf' IN ('wee','wefwf','weg');
1
Type conversion takes place according to the rules described in Section 14.3, “Type Conversion in Expression Evaluation”, applied to all the arguments. If no type conversion is needed for the values in the IN() list, they are all non-JSON constants of the same type, and expr can be compared to each of them as a value of the same type (possibly after type conversion), an optimization takes place. The values the list are sorted and the search for expr is done using a binary search, which makes the IN() operation very quick.
SELECT (3,4) IN ((1,2), (3,4));
1
SELECT (3,4) IN ((1,2), (3,5));
0
IN() can be used to compare row constructors:
SELECT val1 FROM tbl1 WHERE val1 IN (1,2,'a');
You should never mix quoted and unquoted values in an IN() list because the comparison rules for quoted values (such as strings) and unquoted values (such as numbers) differ. Mixing types may therefore lead to inconsistent results. For example, do not write an IN() expression like this:
SELECT val1 FROM tbl1 WHERE val1 IN ('1','2','a');
Instead, write it like this:
SELECT 'a' IN (0), 0 IN ('b');
1, 1