Re: Quick Date/Time Index Question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David Johnston" <polobo(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Quick Date/Time Index Question
Date: 2011-09-22 22:31:14
Message-ID: 12016.1316730674@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"David Johnston" <polobo(at)yahoo(dot)com> writes:
> I have a database field that stores a timestamp to second+ precision;
> however, I want to search against it only to day precision. If I leave the
> field in second precision and try to "WHERE field BETWEEN date0 AND date0" I
> get no results (OK, fine) but then I cast the field to date "WHERE
> field::date BETWEEN date0 AND date0" and get the expected results.

Try "WHERE field BETWEEN date0 AND date0+1". When comparing a date to a
timestamp, the date is considered to represent midnight of its day, so
you're testing for a zero-width range there.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Davis 2011-09-22 22:33:53 Re: Is 9.1 considered more stable/robust than 9.0.4 ?
Previous Message Tom Lane 2011-09-22 22:26:17 Re: Replication between 64/32bit systems?