Re: [SQL] timespan problem - Mailing list pgsql-sql

From Thomas Lockhart
Subject Re: [SQL] timespan problem
Date
Msg-id 3870624A.BA0E8BE5@alumni.caltech.edu
Whole thread Raw
In response to timespan problem  (Tulassay Zsolt <zsolt@tek.bke.hu>)
List pgsql-sql
> The problem appears to be an internal
> overflow in timespan_in...
> 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?

Sure. In the meantime, change the "24" to "24.0" (in the file
src/backend/utils/adt/dt.c around line 2444; hmm, is that line number
a coincidence??) and things will start working :(

btw, there is no possibility for overflow from "time" to "month"; see
below...

> Or is this code all going away in 7.0 anyway?

No, the code is likely to stay since timespan needs to distinguish
between "qualitative time" like months and years and "quantitative
time" like hours and seconds. "time" is stored as a double, but the
calculation was being done with all integers, which lead to the
overflow problem in intermediate results.

Sorry about that. Will commit changes soon.
                     - Thomas

-- 
Thomas Lockhart                lockhart@alumni.caltech.edu
South Pasadena, California


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: [SQL] timespan problem
Next
From: "Wallingford, Ted"
Date:
Subject: restriction clause selectivity bad value