From: Tom Lane <tgl@sss.pgh.pa.us>
To: Antti Haapala <antti.haapala@iki.fi>
Cc: Tomasz Myrta <jasiek@klaster.net>
Cc: PGSQL-SQL <pgsql-sql@postgresql.org>
Subject: Re: casting interval to time
Date: Mon, 16 Jun 2003 15:02:38 -0400
Message-ID: <5949.1055790158@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.GSO.4.55.0306161843230.12828@paju.oulu.fi>
References: <3EEDCB67.4090504@klaster.net>
<2971.1055775231@sss.pgh.pa.us>
<3EEDDB8D.5080401@klaster.net>
<3222.1055776631@sss.pgh.pa.us>
<Pine.GSO.4.55.0306161843230.12828@paju.oulu.fi>
Antti Haapala <antti.haapala@iki.fi> writes:
> It's also Debian (3.0).
On investigation the interval_time() function was completely broken for
the --enable-integer-datetimes case --- it was reducing the interval
value modulo one second, rather than modulo one day as intended.
I also noticed that neither the integer nor float case behaved
rationally for negative intervals. I've applied the attached patch
to 7.3 and HEAD ...
regards, tom lane
inline patch 1: src/backend/utils/adt/date.c (+19/-6 lines) download inline-1.patch*** src/backend/utils/adt/date.c.orig Thu Feb 13 12:04:24 2003
--- src/backend/utils/adt/date.c Mon Jun 16 14:56:53 2003
***************
*** 999,1004 ****
--- 999,1009 ----
/* interval_time()
* Convert interval to time data type.
+ *+ * This is defined as producing the fractional-day portion of the interval.+ * Therefore, we can just ignore the months field. It is not real clear+ * what to do with negative intervals, but we choose to subtract the floor,+ * so that, say, '-2 hours' becomes '22:00:00'.
*/
Datum
interval_time(PG_FUNCTION_ARGS)
***************
*** 1007,1021 ****
TimeADT result;
#ifdef HAVE_INT64_TIMESTAMP
result = span->time;
! if ((result >= INT64CONST(86400000000))
! || (result <= INT64CONST(-86400000000)))
! result -= (result / INT64CONST(1000000) * INT64CONST(1000000));
#else
- Interval span1;-
result = span->time;
! TMODULO(result, span1.time, 86400e0);
#endif
PG_RETURN_TIMEADT(result);
--- 1012,1034 ----
TimeADT result;
#ifdef HAVE_INT64_TIMESTAMP
+ int64 days;+
result = span->time;
! if (result >= INT64CONST(86400000000))
! {
! days = result / INT64CONST(86400000000);
! result -= days * INT64CONST(86400000000);
! }
! else if (result < 0)
! {
! days = (-result + INT64CONST(86400000000-1)) / INT64CONST(86400000000);
! result += days * INT64CONST(86400000000);
! }
#else
result = span->time;
! if (result >= 86400e0 || result < 0)
! result -= floor(result / 86400e0) * 86400e0;
#endif
PG_RETURN_TIMEADT(result);
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: tgl@sss.pgh.pa.us, antti.haapala@iki.fi, jasiek@klaster.net
Subject: Re: casting interval to time
In-Reply-To: <5949.1055790158@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