| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: Efficient date range search?
Pablo Sanchez wrote:
> Kieran <kieran_at_dunelm.org.uk> wrote:
> > Perhaps a bad assumption on my part but I was assuming that we would > only populate the table with pets that have been born. If my > assumption is wrong, then you're totally right, I need to add the > 'born' column in the predicate.
Of course - predicting when babies are going to be born is totally haphazard,in general; they're late, or early, but not on time - especially not to the minute, let alone the second. If the cut-off time is an arbitrary date in the past, though, you have to exclude all the critters born after the cut-off date, whether they are alive or not, just as you have to exclude all critters that died before the cut-off date.
Actually, a better representation for "not died" is a date in the indefinite future - 9999-12-31 23:59:59 perhaps. Yes, you have to worry about the Y10K problem (see RFC 2550 - http://www.faqs.org/rfcs/rfc2550.html) but I plan to take that issue up in 5001-01-01 and no sooner. :-)
Then the criterion for 'alive at time 2001-07-04 19:30:00' is:
WHERE born <= TIMESTAMP '2001-07-04 19:30:00'
AND died >= TIMESTAMP '2001-07-04 19:30:00'
In standard SQL, it gets trickier to express things with one minute granularity. Informix happens to handle that explicitly with a data type (peculiar to Informix) of DATETIME YEAR TO MINUTE.
The standard reference, at least pending C J Date's book on Temporal Databases due out in November, is R T Snodgrass's book "Developing Time-Oriented Database Applications in SQL".
-- Jonathan Leffler #include <disclaimer.h> Email: jleffler_at_earthlink.net, jleffler_at_us.ibm.com Guardian of DBD::Informix 1.00.PC2 -- http://dbi.perl.org/Received on Tue Oct 08 2002 - 00:18:29 CDT
![]() |
![]() |