pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Jan Bodey <jan_bodey@hotmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Date comparison question
Date: Tue, 20 May 2003 09:57:26 -0700 (PDT)
Message-ID: <20030520095059.Q68048-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <Law11-F4684J5kbuOAb0001655b@hotmail.com>

On Tue, 20 May 2003, Jan Bodey wrote:

> Hi
>
> I require a query that will see if a stored date is more than a certain
> interval before the current date.  Using an interval of 10 hours, the query
> would be something like:
>
> SELECT * FROM utable
> WHERE now() - utimestamp > interval '10 hours';
>
> The problem I am having is that the interval is not fixed, and I would like
> to be able to store it as a value in a database table.  The unit of the
> interval can, however, be fixed, and will almost certainly be fixed to
> hours.
>
> I have not been able to find a way of doing what I require, does anybody
> have any ideas to what I need to do?

If you assume that you're just going to stick one row in the interval
table, I think you can do something kinda like:

 create table interv(i interval);
 insert into interv values ('10 hours');
 analyze interv;
 select utable.* from utable, interv
  where now()-utimestamp>i;

This could be made more complicated if you want to have multiple interval
values, etc.  Also, neither of the above is probably terribly fast if
utable is big.




view thread (4+ messages)  latest in thread

Message-ID: <20030520095059.Q68048-100000@megazone23.bigpanda.com>
Permalink:  ../20030520095059.Q68048-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20030520095059.Q68048-100000@megazone23.bigpanda.com

 · 

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: sszabo@megazone23.bigpanda.com, jan_bodey@hotmail.com
  Subject: Re: Date comparison question
  In-Reply-To: <20030520095059.Q68048-100000@megazone23.bigpanda.com>

* 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