In other constellations (typed array value / you want a different type / ARRAY constructor for a non-default type) you may need to cast explicitly.
Rows with id IS NULL
do not pass either of these expressions. To include NULL
values additionally:
SELECT * FROM tbl WHERE (id = ANY ('{1, 2}')) IS NOT TRUE;
There are two obvious points, as well as the points in the other answer:
They are exactly equivalent when using sub queries:
SELECT * FROM tableWHERE column IN(subquery);SELECT * FROM tableWHERE column = ANY(subquery);
On the other hand:
Only the IN
operator allows a simple list:
SELECT * FROM tableWHERE column IN(… , … , …);
Presuming they are exactly the same has caught me out several times when forgetting that ANY
doesn’t work with lists.
'in'
is syntaxis sugar, you can take a look to plan analyse and will see that 'in'
will be transform to =ANY('...,...')::yourType[]