Re: Between with a list of ranges possible ?

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Between with a list of ranges possible ?
Date: 2015-05-29 17:46:00
Message-ID: 5568A5D8.1080104@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 5/29/2015 10:41 AM, John R Pierce wrote:
> On 5/29/2015 9:32 AM, Arup Rakshit wrote:
>> Can I do the below 3 queries in a single query ?
>>
>> select * from table where number * 3 between start_value1 and
>> end_value2;
>> select * from table where number * 3 between start_value2 and
>> end_value2;
>> select * from table where number * 3 between start_value3 and
>> end_value3;
>
> select * from table where (number * 3 between start_value1 and
> end_value2) OR
> (number * 3 between start_value2 and end_value2) OR
> (number * 3 between start_value3 and end_value3);

oh, do note, this won't be /exactly/ the same if the ranges overlap.
your first would return the overlapping rows for each query, while the
OR version will just return one of each row that is in any of the ranges.

--
john r pierce, recycling bits in santa cruz

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephen Cook 2015-05-29 17:48:43 Re: Between with a list of ranges possible ?
Previous Message Raymond O'Donnell 2015-05-29 17:45:47 Re: Between with a list of ranges possible ?