Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: WHERE clause OR vs IN



Richard Broersma Jr <rabroersma(at)yahoo(dot)com> writes:
> --- On Wed, 12/12/07, Medi Montaseri <montaseri(at)gmail(dot)com> wrote:
>> based on your report, run time of OR is 0.275 ms and IN is
>> 0.314
>> 
> postgres=# explain analyze select * from tellers where
>> bid in ('1','2');
 
> Two other options are:

> SELECT *
>   FROM Tellers
>  WHERE bin = ANY( '1', '2' );

Note that depending on which PG version you are testing, x IN (a,b,c)
is exactly equivalent to x=a OR x=b OR x=c (older versions), or to
x = ANY(ARRAYa,b,c]) (newer versions).

>     SELECT T.*
>       FROM Tellers AS T
> INNER JOIN ( VALUES ( '1' ), ( '2' ) ) AS B( bin )
>         ON T.bin = B.bin;

I seriously doubt that one's gonna win ...

			regards, tom lane



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group