Re: WHERE clause with 40+ conditions

From: Binand Sethumadhavan <binand(at)gmx(dot)net>
To: DrYSG <ygutfreund(at)draper(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: WHERE clause with 40+ conditions
Date: 2012-05-05 09:07:50
Message-ID: CAFBJCCY08UMyHL63MG3rcU6dSSjTT2aRZh=zQT-keo2DVP9KFQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On 5 May 2012 00:01, DrYSG <ygutfreund(at)draper(dot)com> wrote:
> My users are presented with a list of checkbox for 4 different attributes
> (e.g. type of image, country, etc.)
>
> Suggestions?

Not as a DB guy, but as a software guy, I might implement something
along these lines:

Create a bit array for each of the attribute, of sufficient length.
Then assign one bit for each value. Assuming this is an image search
system, and you want to search for PNG, JPG and GIF images, create a
3-bit array, with bit 0 turned on means include PNG in search, bit 1
turned on means include JPG in search and bit 2 turned on means
include GIF In search. So, based on what the user selects, you will
get a 3-bit number for image format. Similarly, create n-bit numbers
for each of the other attributes. At the end, concatenate all of them
to get one large N-bit number.

Also, at the time of storing an image, I would populate such an N-bit
number for each image, based on the attributes that are set for that
particular image.

Now, my query will have just one WHERE clause which would look like:

WHERE bitfield_stored_in_db & bitfield_from_search_form <> 0;

Binand

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Ilija Vidoevski 2012-05-05 11:00:32 execute stored function from ms visual foxpro
Previous Message DrYSG 2012-05-04 18:31:51 WHERE clause with 40+ conditions