Re: More efficient OR

From: "Keith Worthington" <keithw(at)narrowpathinc(dot)com>
To: "PostgreSQL SQL" <pgsql-sql(at)postgresql(dot)org>
Cc: "Sean Davis" <sdavis2(at)mail(dot)nih(dot)gov>, "Scott Marlowe" <smarlowe(at)g2switchworks(dot)com>
Subject: Re: More efficient OR
Date: 2005-02-16 16:35:30
Message-ID: 20050216162747.M40986@narrowpathinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> > Hi All,
> >
> > In several of my SQL statements I have to use a WHERE clause
> > that contains mutiple ORs. i.e.
> >
> > WHERE column1 = 'A' OR
> > column1 = 'B' OR
> > column1 = 'C'
> >
> > Is there a more efficient SQL statement that accomplishes the
> > same limiting functionality?
> >
> > Kind Regards,
> > Keith
> >
>
> Scott wrote:
> The in() construct is (nowadays) basically the same as
> ORing multiple columns;
>
> where column1 in ('A','B','C')
>
>
> Sean Davis wrote
> Could 'in' or 'between' do what you want? I know that using 'in'
> is equivalent to what you have below. Could 'between' be more
> efficient--you could do explain analyze on various options to see
> what the actual plan would be.
>
> Sean

Thanks Scott and Sean for the post.

It sounds like IN will save some typing and code space but not decrease the
execution time.

BETWEEN won't work for my real life query because the limiting values are
quite disparate.

Kind Regards,
Keith

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message lucas 2005-02-16 16:43:01 Relation in tables
Previous Message Sean Davis 2005-02-16 16:21:01 Re: More efficient OR