Postgres is the database
Can I use a NULL value for a IN clause? example:
SELECT *
FROM tbl_name
WHERE id_field IN (\'value1\', \'value2\', \'value3\
Your query fails due to operator precedence. AND
binds before OR
!
You need a pair of parentheses, which is not a matter of "clarity", but pure logic necessity.
SELECT *
FROM tbl_name
WHERE other_condition = bar
AND another_condition = foo
AND (id_field IN ('value1', 'value2', 'value3') OR id_field IS NULL)
The added parentheses prevent AND
binding before OR
. If there were no other WHERE
conditions (no AND
) you would not need parentheses. The accepted answer is a bit misleading in this respect.