RE: Large OR query - Mailing list pgsql-general

From Jeff Eckermann
Subject RE: Large OR query
Date
Msg-id 08CD1781F85AD4118E0800A0C9B8580B094AD2@NEZU
Whole thread Raw
In response to Large OR query  (Zak McGregor <zak@mighty.co.za>)
List pgsql-general
I would load the 1000 values into a temporary table, and join on the ID
field.  I usually find that approach gives much faster results.

> -----Original Message-----
> From:    Zak McGregor [SMTP:zak@mighty.co.za]
> Sent:    Tuesday, June 12, 2001 7:42 AM
> To:    pgsql-general@postgresql.org
> Subject:    [GENERAL] Large OR query
>
> Hi all
>
> If I have say 1000 values for an ID field, what is the best way to
> select from a table all the corresponding records?
> I have tried
> select * from blah where id in (id1,id2,id3...id1000)
> and
> select * from blah where id=id1 or id=id2 ... or id=id1000
>
> and both are pretty slow.
> Is there a better way to do this please?
>
> Thanks
>
> Ciao
> --
> Zak McGregor    http://www.carfolio.com - Over 7000 car specs online
> Web mercenary - currently for hire. Perl/html/.js/sql/cgi/GNUlinux/php +
> ---------------------------------------------------------------------
> "Trying to make bits uncopyable is like trying to make water not wet.
> The sooner people accept this, and build business models that take
> this into account, the sooner people will start making money again."
>                             -- Bruce Schneier
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl

pgsql-general by date:

Previous
From: Zak McGregor
Date:
Subject: Large OR query
Next
From: Tom Lane
Date:
Subject: Re: [NOVICE] PostgreSQL problem with functions