pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Keith Worthington <keithw@narrowpathinc.com>
To: PostgreSQL SQL <pgsql-sql@postgresql.org>
Cc: Sean Davis <sdavis2@mail.nih.gov>
Cc: Scott Marlowe <smarlowe@g2switchworks.com>
Subject: Re: More efficient OR
Date: Wed, 16 Feb 2005 11:35:30 -0500
Message-ID: <20050216162747.M40986@narrowpathinc.com> (raw)
In-Reply-To: <BFC3420B-8036-11D9-B22E-000D933565E8@mail.nih.gov>
References: <20050216155901.M41773@narrowpathinc.com>
	<BFC3420B-8036-11D9-B22E-000D933565E8@mail.nih.gov>

> > 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



view thread (7+ messages)  latest in thread

Message-ID: <20050216162747.M40986@narrowpathinc.com>
Permalink:  ../20050216162747.M40986@narrowpathinc.com/
Also on:    postgresql.org/message-id/20050216162747.M40986@narrowpathinc.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: keithw@narrowpathinc.com, sdavis2@mail.nih.gov, smarlowe@g2switchworks.com
  Subject: Re: More efficient OR
  In-Reply-To: <20050216162747.M40986@narrowpathinc.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox