Re: [GENERAL] query for a time interval

2005-12-23 Thread Bruno Wolff III
On Wed, Dec 21, 2005 at 11:52:56 -0800, Mark <[EMAIL PROTECTED]> wrote: > Hello everybody, > > I'm looking for an elegant SQL statement that will work in > Postgresql, MySQL and ORACLE. > The query will be executed by Java client. > > To have this query for Postgresql is priority number one. >

Re: [GENERAL] query for a time interval

2005-12-23 Thread Tom Lane
Michael Fuhr <[EMAIL PROTECTED]> writes: > Unless I'm missing something that wouldn't use an index either, > because the planner wouldn't know what value to compare start_date > against without hitting each row to find that row's time_to_live. > But something like this should be able to use an expr

Re: [GENERAL] query for a time interval

2005-12-22 Thread Michael Fuhr
On Thu, Dec 22, 2005 at 09:47:11AM -0600, Jim C. Nasby wrote: > 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), wh

Re: [GENERAL] query for a time interval

2005-12-22 Thread Jim C. Nasby
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_da

[GENERAL] query for a time interval

2005-12-21 Thread Mark
Hello everybody, I'm looking for an elegant SQL statement that will work in Postgresql, MySQL and ORACLE. The query will be executed by Java client. To have this query for Postgresql is priority number one. In this query I try to get a list of message Ids that expired. time_to_live is in secon