calculated expressions and index use

From: Pavel Hlavnicka <pavel(at)gingerall(dot)cz>
To: pgsql-sql(at)postgresql(dot)org
Subject: calculated expressions and index use
Date: 2003-01-30 15:54:14
Message-ID: 3E394AA6.8080400@gingerall.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

--
Pavel Hlavnicka
Ginger Alliance
www.gingerall.com

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2003-01-30 16:00:07 Re: Delete 1 Record of 2 Duplicate Records
Previous Message Tom Lane 2003-01-30 15:39:59 Re: Question about passing User defined types to functions