Re: date ranges in where

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Erik Jones <ejones(at)engineyard(dot)com>
Cc: Adrian Klaver <aklaver(at)comcast(dot)net>, pgsql-general(at)postgresql(dot)org, Miguel Miranda <miguel(dot)mirandag(at)gmail(dot)com>
Subject: Re: date ranges in where
Date: 2009-05-07 01:50:11
Message-ID: 4A023E53.5040007@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Erik Jones wrote:
>
> On May 6, 2009, at 2:19 PM, Adrian Klaver wrote:
>
>> On Wednesday 06 May 2009 2:12:47 pm Miguel Miranda wrote:
>>> Hi, what is the recommended way to select a range of dates?
>>>
>>> Lets say a have a table with a lastlogin (timestamp) column and i want
>>> toknow what users logged in for last time between 2009-05-01 and
>>> 2009-05-02?
>>>
>>> I know that a simple
>>>
>>> where lastlogin between '2009-05-01' and '2009-05-02' doesnt work
>>> beacuse
>>> it doesnt include who logged in 2009-05-02 15:30:00, etc...
>>
>> lastlogin between '2009-05-01' AND '2009-05-03'
>
> Technically, BETWEEN is inclusive of the two values given so that would
> also match '2009-05-03 00:00:00'.

It would be kind of nice to have a right-exclusive BETWEEN. I've had a
few situations like this come up, and while it's not a big deal to do, eg:

SELECT ... WHERE x BETWEEN start_time
AND end_time + '1 day' - '0.00001 seconds'::interval;

... it'd be nicer (and less sensitive to timestamp precision issues) to
just have a BETWEEN RIGHT EXCLUSIVE or similar.

--
Craig Ringer

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2009-05-07 02:04:24 Re: PgUS 501c3 Public Charity
Previous Message Craig Ringer 2009-05-07 01:35:26 Re: Transaction settings: nowait