Re: Is This A Set Based Solution? - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: Is This A Set Based Solution?
Date
Msg-id 20070315204633.GA2156@wolff.to
Whole thread Raw
In response to Re: Is This A Set Based Solution?  (Stefan Berglund <sorry.no.koolaid@for.me>)
Responses Re: Is This A Set Based Solution?  (Tino Wildenhain <tino@wildenhain.de>)
List pgsql-general
On Mon, Mar 12, 2007 at 11:15:01 -0700,
  Stefan Berglund <sorry.no.koolaid@for.me> wrote:
>
> I have an app where the user makes multiple selections from a list.  I
> can either construct a huge WHERE clause such as SELECT blah blah FROM
> foo WHERE (ID = 53016 OR ID = 27 OR ID = 292 OR ID = 512) or I could
> alternatively pass the string of IDs ('53016,27,292,512') to a table
> returning function which TABLE is then JOINed with the table I wish to
> query instead of using the unwieldy WHERE clause.  The latter strikes me
> as a far more scalable method since it eliminates having to use dynamic
> SQL to construct the ridiculously long WHERE clause which will no doubt
> ultimately bump up against parser length restrictions or some such.

How big is huge?
If the list of IDs is in the 1000s or higher, then it may be better to
load the data into a temp table and ANALYSE it before running your query.
Otherwise, for smaller lists the IN suggestion should work well in recent
versions.

pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: pg_dumpall and version confusion
Next
From: "Jonah H. Harris"
Date:
Subject: Re: [SQL] PostgreSQL to Oracle