Re: query for a time interval

From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: Mark <sendmailtomark(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: query for a time interval
Date: 2005-12-22 15:47:11
Message-ID: 20051222154711.GW72143@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Dec 21, 2005 at 11:52:56AM -0800, Mark wrote:
> SELECT id
> FROM mq
> WHERE now - start_date > time_to_live;

The problem is you can't use an index on this, because you'd need to
index on (now() - start_date), which obviously wouldn't work. Instead,
re-write the WHERE as:

WHERE start_date < now() - time_to_live
--
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jim C. Nasby 2005-12-22 15:52:05 Re: Is CREATE TYPE an alias for CREATE DOMAIN?
Previous Message Jim C. Nasby 2005-12-22 15:45:12 Re: view or index to optimize performance