pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tulassay Zsolt <zsolt@tek.bke.hu>
Cc: Thomas Lockhart <lockhart@alumni.caltech.edu>
Cc: pgsql-sql@hub.org
Subject: Re: [SQL] timespan problem
Date: Sat, 01 Jan 2000 18:58:30 -0500
Message-ID: <20530.946771110@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.LNX.4.10.10001012142220.17313-100000@tek.bke.hu>
References: <Pine.LNX.4.10.10001012142220.17313-100000@tek.bke.hu>

Tulassay Zsolt <zsolt@tek.bke.hu> writes:
> forum=> select datetime(now())+'74565 days'::timespan as ido;
> ido                                                          
> ------------------------
> Thu Jan 19 14:07:30 2068
> (1 row)                 

> forum=> select datetime(now())+'74566 days'::timespan as ido;
> ido
> ----------------------------                                 
> Tue Dec 15 08:39:21 1931 CET
> (1 row)                     

Of course, both of the above are drastically wrong, since 74575 days
should be upwards of 200 years.  The problem appears to be an internal
overflow in timespan_in, since you can show wrong results just with:

regression=> select '74565 days'::timespan;
?column?
-------------------------------------
@ 24854 days 17 hours 31 mins 44 secs
(1 row)

regression=> select '74566 days'::timespan;
?column?
-----------------------------------------
@ 24854 days 12 hours 56 mins 32 secs ago
(1 row)

Looking into it, the guilty party seems to be tm2timespan() which
blithely assumes that it need not worry about overflow from its
"time" field to its "month" field:

    span->month = ((tm->tm_year * 12) + tm->tm_mon);
    span->time = ((((((tm->tm_mday * 24) + tm->tm_hour) * 60) + tm->tm_min) * 60) + tm->tm_sec);
    span->time = JROUND(span->time + fsec);

Thomas, you want to deal with this one?  Or is this code all going
away in 7.0 anyway?

			regards, tom lane



view thread (5+ messages)  latest in thread

Message-ID: <20530.946771110@sss.pgh.pa.us>
Permalink:  ../20530.946771110@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20530.946771110@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, zsolt@tek.bke.hu, lockhart@alumni.caltech.edu, pgsql-sql@hub.org
  Subject: Re: [SQL] timespan problem
  In-Reply-To: <20530.946771110@sss.pgh.pa.us>
  References: <Pine.LNX.4.10.10001012142220.17313-100000@tek.bke.hu> <20530.946771110@sss.pgh.pa.us>

* 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