Quick Date/Time Index Question - Mailing list pgsql-general

From David Johnston
Subject Quick Date/Time Index Question
Date
Msg-id 004701cc796c$7d9494a0$78bdbde0$@yahoo.com
Whole thread Raw
Responses Re: Quick Date/Time Index Question  (Ben Chobot <bench@silentmedia.com>)
Re: Quick Date/Time Index Question  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Quick Date/Time Index Question  (Michael Glaesemann <grzm@seespotcode.net>)
List pgsql-general

Hey,

 

On 9.0.4

 

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?

 

Thanks in advance.

 

David J.

 

pgsql-general by date:

Previous
From: Greg Smith
Date:
Subject: Re: Materialized views in Oracle
Next
From: Ben Chobot
Date:
Subject: Re: Quick Date/Time Index Question