IN vs ANY operator in PostgreSQL

后端 未结 2 597
挽巷
挽巷 2020-11-27 11:14

What is the difference between IN and ANY operator in PostgreSQL?
The working mechanism of both seems to be the same. Can anyone explain this w

2条回答
  •  旧时难觅i
    2020-11-27 11:28

    There are two obvious points, as well as the points in the other answer:

    • They are exactly equivalent when using sub queries:

      SELECT * FROM table
      WHERE column IN(subquery);
      
      SELECT * FROM table
      WHERE column = ANY(subquery);
      

    On the other hand:

    • Only the IN operator allows a simple list:

      SELECT * FROM table
      WHERE column IN(… , … , …);
      

    Presuming they are exactly the same has caught me out several times when forgetting that ANY doesn’t work with lists.

提交回复
热议问题