14 ms·
IN is not recommended. Use = ANY instead.
by Horffupolde 1y ago
IN is not recommended. Use = ANY instead.
- codesnik 1y agoaren't they the same in Postgres?
- frollogaston 1y agoYes, according to the manual, IN is equivalent to = ANY() https://www.postgresql.org/docs/current/functions-subquery.html#FUNCTIONS-SUBQUERY-ANY-SOME https://www.postgresql.org/docs/current/functions-subquery.h... I had to check because for some reason, I always thought =ANY was somehow better than IN.
- masklinn 1y agoIt is, but in a pretty minor way: any can be used with no items, IN can not and will error.
- tczMUFlmoNk 1y agoANY can be used with arrays, particularly query parameters: `id = ANY($1::int[])`, but not `id IN $1::int[]`.
- frollogaston 1y agoOh that must be why I got into this habit.
- Sesse__ 1y agoIN is fine. The biggest problem comes with NOT IN, which has NULL semantics that makes life difficult for the planner. It is consistent but rarely what the user wants. NOT EXISTS is typically better there.