Обсуждение: Handling Time

Поиск
Список
Период
Сортировка

Handling Time

От
Дата:
i'm wanting to timestamp database entries and i would
appreciate some feedback from the collective wisdom of
this thread.

what is the best way to do this?  are ther pitfalls to
avoid.

i have started using date, but thought there was a
remote chance i might need time, also.  is the db load
of storing time great enough that it isn't worth
storing time based on remote chances it *might* be
valuable?

tia...



__________________________________
Do you Yahoo!?
Yahoo! Personals - Better first dates. More second dates.
http://personals.yahoo.com


Re: Handling Time

От
Aarni Ruuhimäki
Дата:
Hi,

Don't worry about the 'load', it's peanuts to pg.

Here's something on the subject from the past.

BR,

Aarni

>>>> begin quote >>>>

> The issue is not really what the raw timestamp value's range is.
> The issue is what range of dates do you have local timezone information
> for.  Pay close attention to the difference here:
>
> regression=# select '1999-09-27'::timestamp with time zone;
>       timestamptz
> ------------------------
>  1999-09-27 00:00:00-04
> (1 row)
>
> regression=# select '2999-09-27'::timestamp with time zone;
>      timestamptz
> ---------------------
>  2999-09-27 00:00:00
> (1 row)
>
> PG is refusing to assign a time zone to the latter.  The reason: our
> present code relies on the surrounding Unix system to provide timezone
> data, and it does so through Unix APIs that (on most boxen) overflow in
> 2038.  Thus the above behavior.
>
> However, before panicking over that limitation, you should ask yourself
> what you will bet that the politicians in your country won't have
> changed your daylight-savings rules in the next 35 years.  Or for that
> matter, do you know when the next leap-second insertion will be, or if
> there will be any more at all?  We may know now how far away we think
> "May 1, 10000 AD" is, but what are the odds that people in 10000 AD
> will
> still use the Gregorian calendar (which is less than 400 years old
> IIRC)?
> Civil calendars both past and future are so uncertain that you
> shouldn't
> get too excited about these issues...


Ah, I see.   I don't use timestamp with timezone much; I find the Unix
implementation of time zones inadequate for reality.

So, the answer is that TIMESTAMP WITH TIMEZONE is good through 2037, and
TIMESTAMP WITHOUT TIME ZONE is good through 10,000AD?

And, on the up side, if the various *nixes fix their time zone behaviour past
2037, then Postgres will be automatically fixed as well, yes?

>Depends what the new API looks like.  I would think that a sane answer
>is to redefine time_t as a signed 64-bit value, preserving the 1/1/1970
>zero origin, but who knows what the library people will really do?
>glibc's recent move to redefine time_t as unsigned (losing support for
>all pre-1970 dates) doesn't give me high confidence in their design
>sensibility.

>>>> end quote >>>>

On Friday 01 April 2005 08:20, you wrote:
> i'm wanting to timestamp database entries and i would
> appreciate some feedback from the collective wisdom of
> this thread.
>
> what is the best way to do this?  are ther pitfalls to
> avoid.
>
> i have started using date, but thought there was a
> remote chance i might need time, also.  is the db load
> of storing time great enough that it isn't worth
> storing time based on remote chances it *might* be
> valuable?
>
> tia...
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Personals - Better first dates. More second dates.
> http://personals.yahoo.com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster


--------------
This is a bugfree broadcast to you
from **Kmail**
on **Fedora Core 2** linux system
--------------

Re: Handling Time

От
Tom Lane
Дата:
Aarni =?iso-8859-1?q?Ruuhim=E4ki?= <aarni@kymi.com> writes:
> So, the answer is that TIMESTAMP WITH TIMEZONE is good through 2037, and
> TIMESTAMP WITHOUT TIME ZONE is good through 10,000AD?

That was a reasonable answer at the time of the message you quote, but
PG 8.0 no longer relies on the OS for timezone support.  So now, to
repeat the example:

regression=# select '1999-09-27'::timestamp with time zone;
      timestamptz
------------------------
 1999-09-27 00:00:00-04
(1 row)

regression=# select '2999-09-27'::timestamp with time zone;
      timestamptz
------------------------
 2999-09-27 00:00:00-05
(1 row)

or for that matter

regression=# select '0099-09-27 BC'::timestamp with time zone;
        timestamptz
---------------------------
 0099-09-27 00:00:00-05 BC
(1 row)

The points I made before about the dubiousness of this calculation are
as valid as ever, but it's no longer a matter of not being able to do
it, it's just a matter of how much space you want to expend in the
timezone data files.  (The first and last dates shown above are outside
the range of the Americas/New_York timezone file that we supply, so PG
falls back to assuming local standard time.)

            regards, tom lane