Re: Optimization with dates - Mailing list pgsql-sql

From caldodge@fpcc.net (Calvin Dodge)
Subject Re: Optimization with dates
Date
Msg-id ca6275f0.0111201628.6d3bda77@posting.google.com
Whole thread Raw
In response to Optimization with dates  (Jean-Christophe Boggio <cat@thefreecat.org>)
List pgsql-sql
cat@thefreecat.org (Jean-Christophe Boggio) wrote in message news:<72319017913.20011114005656@thefreecat.org>...
> I have tried :
>   where dategain>=(select now()-30);
>   where dategain+30>='now'
>   where date(dategain)>=date('now')-30
>   and many other, syntactically absurd :-)
>
> Anyone can help me use this index ?

From my brief experiments, it _looks_ like the optimizer uses index
scan on dates only when those dates are constant (in my case, anyway -
as always, YMMV).

I tried functions, variables, and using both upper and lower limits.

The only time index scanning was used (according to "explain") was
when I used constant values for the dates.

So ... do you _have_ to do your querying in psql?  Or will your
application permit you to create queries with embedded constant date
values in the Planguage (PHP, Python, Perl) of your choice?


Calvin


pgsql-sql by date:

Previous
From: caldodge@fpcc.net (Calvin Dodge)
Date:
Subject: Re: SELECT * FROM t where p or q;
Next
From: Gurudutt
Date:
Subject: Joins~