Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
Horffupolde
1 day ago
|
parent
|
context
|
favorite
| on:
A PostgreSQL planner semi-join gotcha with CTE, LI...
IN is not recommended. Use = ANY instead.
codesnik
1 day ago
[–]
aren't they the same in Postgres?
reply
frollogaston
1 day ago
|
parent
[–]
Yes, according to the manual, IN is equivalent to = ANY()
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.
reply
Sesse__
1 day ago
|
root
|
parent
|
next
[–]
IN 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.
reply
tczMUFlmoNk
1 day ago
|
root
|
parent
|
prev
|
next
[–]
ANY can be used with arrays, particularly query parameters: `id = ANY($1::int[])`, but not `id IN $1::int[]`.
reply
frollogaston
14 hours ago
|
root
|
parent
|
next
[–]
Oh that must be why I got into this habit.
reply
masklinn
1 day ago
|
root
|
parent
|
prev
[–]
It is, but in a pretty minor way: any can be used with no items, IN can not and will error.
reply
Join us for
AI Startup School
this June 16-17 in San Francisco!
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: