Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 518044770B0 for ; Thu, 30 Jan 2003 11:17:20 -0500 (EST) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id DED6D4770A5 for ; Thu, 30 Jan 2003 11:17:19 -0500 (EST) Received: by news.hub.org (Postfix, from userid 8) id BE72D43A90B; Thu, 30 Jan 2003 11:17:19 -0500 (EST) From: Arjen van der Meijden X-Newsgroups: comp.databases.postgresql.sql Subject: Re: calculated expressions and index use Date: Thu, 30 Jan 2003 17:13:40 +0100 Organization: Delft University of Technology Lines: 36 Message-ID: References: <3E394AA6.8080400@gingerall.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.tudelft.nl User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en In-Reply-To: <3E394AA6.8080400@gingerall.cz> To: pgsql-sql@postgresql.org X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/507 X-Sequence-Number: 11372 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 >