Re: Comparing dates

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "John Velman" <velman(at)cox(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Comparing dates
Date: 2003-09-04 04:11:32
Message-ID: 10559.1062648692@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"John Velman" <velman(at)cox(dot)net> writes:
> When I do a select such as
> SELECT * FROM table WHERE date BETWEEN '2001-12-28' AND '2002-01-28'
> It misses the entry with date '2002-01-28' (which does exist!).

Uh, what exactly is the datatype of the "date" column?

> The only way I've been able to handle this, so far, is
> in this fashion:
> SELECT * FROM table WHERE
> date BETWEEN 20011228 - .001 AND 20020128 + .001 ;

I think the odds that this does what you think it does are vanishingly
small :-(. There's no date-vs-numeric comparison operator. It's
probably getting interpreted as some bizarre textual comparison.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-09-04 04:12:32 Re: TCL trigger doesn't work after deleting a column
Previous Message Tom Lane 2003-09-04 03:27:16 Re: Index not being used ?