pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Arjen van der Meijden <acm@tweakers.net>
To: pgsql-sql@postgresql.org
Subject: Re: calculated expressions and index use
Date: Thu, 30 Jan 2003 17:13:40 +0100
Message-ID: <b1biv3$l4s$1@news.tudelft.nl> (raw)
In-Reply-To: <3E394AA6.8080400@gingerall.cz>
References: <3E394AA6.8080400@gingerall.cz>

A very dirty work around could be:
select * from foo where created+at >= (select now() - '1 hour'::interval);

Or perhaps this already works:
select * from foo where created+at >= (now() - '1 hour'::interval);

Pavel Hlavnicka wrote:
> Hi all,
> 
> I use simple sql statement like this
> 
> select * from foo
> where created_at >= 'now'::timestamp - '1 hour'::interval;
> 
> My table is indexed on created_at field. The query above doesn't use it, 
> but if I use
> 
> select * from foo where created_at >= 'now'
> 
> the index is used.
> 
> It looks like if the engine finds some expression to be evaluated it 
> gets rid of any index use (due the possible dependency?).
> 
> Is it possible to do something to 'precompute' some value in the query 
> condition, so planner understand is as a constant value?
> 
> (... and I've got some reason NOT to use a parameter in my Perl DBI code...)
> 
> Maybe my conclusions are wrong, of course.
> 
> Thank you very much in advance
> 
> Pavel
> 




view thread (6+ messages)  latest in thread

Message-ID: <b1biv3$l4s$1@news.tudelft.nl>
Permalink:  ../b1biv3$l4s$1@news.tudelft.nl/
Also on:    postgresql.org/message-id/b1biv3$l4s$1@news.tudelft.nl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: acm@tweakers.net
  Subject: Re: calculated expressions and index use
  In-Reply-To: <b1biv3$l4s$1@news.tudelft.nl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox