PostgreSQL – IN vs ANY

No, in these variants are same: You can see – the execution plans are same too: postgres=# explain select * from foo1 where id in (select id from foo2); ┌──────────────────────────────────────────────────────────────────┐ │ QUERY PLAN │ ╞══════════════════════════════════════════════════════════════════╡ │ Hash Semi Join (cost=3.25..21.99 rows=100 width=4) │ │ Hash Cond: (foo1.id = foo2.id) │ │ -> Seq Scan on … Read more

IN vs ANY operator in PostgreSQL

(Strictly speaking, IN and ANY are Postgres “constructs” or “syntax elements”, rather than “operators”.) Logically, quoting the manual: IN is equivalent to = ANY. But there are two syntax variants of IN and two variants of ANY. Details: How to use ANY instead of IN in a WHERE clause? IN taking a set is equivalent … Read more

Difference between EXISTS and IN in SQL?

The exists keyword can be used in that way, but really it’s intended as a way to avoid counting: –this statement needs to check the entire table select count(*) from [table] where … –this statement is true as soon as one match is found exists ( select * from [table] where … ) This is … Read more