From: | Tim Landscheidt <tim(at)tim-landscheidt(dot)de> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Quick Date/Time Index Question |
Date: | 2011-09-22 22:22:50 |
Message-ID: | m3obyc8bet.fsf@passepartout.tim-landscheidt.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"David Johnston" <polobo(at)yahoo(dot)com> wrote:
> 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. So now I
> want to index "field::date" by I cannot create a functional index on
> "field::date" OR "CAST(field AS date)" OR "date_trunc('day',field)" due to
> either syntax (::) or non-IMMUTABLE function errors (cast; date_trunc).
> Is there some other way to create an index on only the "date" portion of the
> field? Is it even necessary since any index ordered on timestamp is also,
> by definition, order on date as well?
Not necessarily a direct answer, but have you tried querying
"WHERE field >= date0 AND field < (date0 + 1)"?
Tim
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2011-09-22 22:26:17 | Re: Replication between 64/32bit systems? |
Previous Message | Michael Glaesemann | 2011-09-22 22:19:50 | Re: Quick Date/Time Index Question |