Commit 547df0cc authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Support alternate storage scheme of 64-bit integer for date/time types.

 Use "--enable-integer-datetimes" in configuration to use this rather
 than the original float8 storage. I would recommend the integer-based
 storage for any platform on which it is available. We perhaps should
 make this the default for the production release.
Change timezone(timestamptz) results to return timestamp rather than
 a character string. Formerly, we didn't have a way to represent
 timestamps with an explicit time zone other than freezing the info into
 a string. Now, we can reasonably omit the explicit time zone from the
 result and return a timestamp with values appropriate for the specified
 time zone. Much cleaner, and if you need the time zone in the result
 you can put it into a character string pretty easily anyway.
Allow fractional seconds in date/time types even for dates prior to 1BC.
Limit timestamp data types to 6 decimal places of precision. Just right
 for a micro-second storage of int8 date/time types, and reduces the
 number of places ad-hoc rounding was occuring for the float8-based types.
Use lookup tables for precision/rounding calculations for timestamp and
 interval types.  Formerly used pow() to calculate the desired value but
 with a more limited range there is no reason to not type in a lookup
 table. Should be *much* better performance, though formerly there were
 some optimizations to help minimize the number of times pow() was called.
Define a HAVE_INT64_TIMESTAMP variable. Based on the configure option
 "--enable-integer-datetimes" and the existing internal INT64_IS_BUSTED.
Add explicit date/interval operators and functions for addition and
 subtraction. Formerly relied on implicit type promotion from date to
 timestamp with time zone.
Change timezone conversion functions for the timetz type from "timetz()"
 to "timezone()". This is consistant with other time zone coersion
 functions for other types.
Bump the catalog version to 200204201.
Fix up regression tests to reflect changes in fractional seconds
 representation for date/times in BC eras.
All regression tests pass on my Linux box.
parent 3fab4932
This diff is collapsed.
This diff is collapsed.
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
* formatting.c * formatting.c
* *
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.52 2002/04/03 05:39:29 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.53 2002/04/21 19:48:12 thomas Exp $
* *
* *
* Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group * Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group
...@@ -410,7 +410,7 @@ typedef struct ...@@ -410,7 +410,7 @@ typedef struct
typedef struct TmToChar typedef struct TmToChar
{ {
struct tm tm; /* classic 'tm' struct */ struct tm tm; /* classic 'tm' struct */
double fsec; /* milliseconds */ fsec_t fsec; /* fractional seconds */
char *tzn; /* timezone */ char *tzn; /* timezone */
} TmToChar; } TmToChar;
...@@ -1831,7 +1831,11 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data) ...@@ -1831,7 +1831,11 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
case DCH_MS: /* millisecond */ case DCH_MS: /* millisecond */
if (flag == TO_CHAR) if (flag == TO_CHAR)
{ {
#ifdef HAVE_INT64_TIMESTAMP
sprintf(inout, "%03d", (int) (tmtc->fsec / INT64CONST(1000)));
#else
sprintf(inout, "%03d", (int) rint(tmtc->fsec * 1000)); sprintf(inout, "%03d", (int) rint(tmtc->fsec * 1000));
#endif
if (S_THth(suf)) if (S_THth(suf))
str_numth(p_inout, inout, S_TH_TYPE(suf)); str_numth(p_inout, inout, S_TH_TYPE(suf));
if (S_THth(suf)) if (S_THth(suf))
...@@ -1874,7 +1878,11 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data) ...@@ -1874,7 +1878,11 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
case DCH_US: /* microsecond */ case DCH_US: /* microsecond */
if (flag == TO_CHAR) if (flag == TO_CHAR)
{ {
#ifdef HAVE_INT64_TIMESTAMP
sprintf(inout, "%06d", (int) tmtc->fsec);
#else
sprintf(inout, "%06d", (int) rint(tmtc->fsec * 1000000)); sprintf(inout, "%06d", (int) rint(tmtc->fsec * 1000000));
#endif
if (S_THth(suf)) if (S_THth(suf))
str_numth(p_inout, inout, S_TH_TYPE(suf)); str_numth(p_inout, inout, S_TH_TYPE(suf));
if (S_THth(suf)) if (S_THth(suf))
...@@ -2868,7 +2876,7 @@ to_timestamp(PG_FUNCTION_ARGS) ...@@ -2868,7 +2876,7 @@ to_timestamp(PG_FUNCTION_ARGS)
date_len, date_len,
tz = 0; tz = 0;
struct tm tm; struct tm tm;
double fsec = 0; fsec_t fsec = 0;
ZERO_tm(&tm); ZERO_tm(&tm);
ZERO_tmfc(&tmfc); ZERO_tmfc(&tmfc);
...@@ -3071,10 +3079,17 @@ to_timestamp(PG_FUNCTION_ARGS) ...@@ -3071,10 +3079,17 @@ to_timestamp(PG_FUNCTION_ARGS)
tm.tm_yday - y[i - 1]; tm.tm_yday - y[i - 1];
} }
#ifdef HAVE_INT64_TIMESTAMP
if (tmfc.ms)
fsec += tmfc.ms * 1000;
if (tmfc.us)
fsec += tmfc.us;
#else
if (tmfc.ms) if (tmfc.ms)
fsec += (double) tmfc.ms / 1000; fsec += (double) tmfc.ms / 1000;
if (tmfc.us) if (tmfc.us)
fsec += (double) tmfc.us / 1000000; fsec += (double) tmfc.us / 1000000;
#endif
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.37 2002/02/23 01:01:30 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.38 2002/04/21 19:48:12 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
/* this should be set in pg_config.h, but just in case it wasn't: */ /* this should be set in pg_config.h, but just in case it wasn't: */
#ifndef INT64_FORMAT #ifndef INT64_FORMAT
#warning "Broken pg_config.h should have defined INT64_FORMAT"
#define INT64_FORMAT "%ld" #define INT64_FORMAT "%ld"
#endif #endif
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.92 2002/03/06 06:10:13 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.93 2002/04/21 19:48:12 thomas Exp $
* *
* NOTES * NOTES
* *
...@@ -76,21 +76,6 @@ ...@@ -76,21 +76,6 @@
AbsoluteTimeGetDatum(t1), \ AbsoluteTimeGetDatum(t1), \
AbsoluteTimeGetDatum(t2))) ? (t2) : (t1)) AbsoluteTimeGetDatum(t2))) ? (t2) : (t1))
#ifdef NOT_USED
static char *unit_tab[] = {
"second", "seconds", "minute", "minutes",
"hour", "hours", "day", "days", "week", "weeks",
"month", "months", "year", "years"};
#define UNITMAXLEN 7 /* max length of a unit name */
#define NUNITS 14 /* number of different units */
/* table of seconds per unit (month = 30 days, year = 365 days) */
static int sec_tab[] = {
1, 1, 60, 60,
3600, 3600, 86400, 86400, 604800, 604800,
2592000, 2592000, 31536000, 31536000};
#endif
/* /*
* Function prototypes -- internal to this file only * Function prototypes -- internal to this file only
...@@ -98,12 +83,6 @@ static int sec_tab[] = { ...@@ -98,12 +83,6 @@ static int sec_tab[] = {
static AbsoluteTime tm2abstime(struct tm * tm, int tz); static AbsoluteTime tm2abstime(struct tm * tm, int tz);
static void reltime2tm(RelativeTime time, struct tm * tm); static void reltime2tm(RelativeTime time, struct tm * tm);
#ifdef NOT_USED
static int correct_unit(char *unit, int *unptr);
static int correct_dir(char *direction, int *signptr);
#endif
static int istinterval(char *i_string, static int istinterval(char *i_string,
AbsoluteTime *i_start, AbsoluteTime *i_start,
AbsoluteTime *i_end); AbsoluteTime *i_end);
...@@ -177,7 +156,7 @@ GetCurrentAbsoluteTime(void) ...@@ -177,7 +156,7 @@ GetCurrentAbsoluteTime(void)
} /* GetCurrentAbsoluteTime() */ } /* GetCurrentAbsoluteTime() */
/* GetCurrentAbsoluteTime() /* GetCurrentAbsoluteTimeUsec()
* Get the current system time. Set timezone parameters if not specified elsewhere. * Get the current system time. Set timezone parameters if not specified elsewhere.
* Define HasCTZSet to allow clients to specify the default timezone. * Define HasCTZSet to allow clients to specify the default timezone.
* *
...@@ -271,13 +250,17 @@ GetCurrentTime(struct tm * tm) ...@@ -271,13 +250,17 @@ GetCurrentTime(struct tm * tm)
void void
GetCurrentTimeUsec(struct tm * tm, double *fsec) GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec)
{ {
int tz; int tz;
int usec; int usec;
abstime2tm(GetCurrentTransactionStartTimeUsec(&usec), &tz, tm, NULL); abstime2tm(GetCurrentTransactionStartTimeUsec(&usec), &tz, tm, NULL);
#ifdef HAVE_INT64_TIMESTAMP
*fsec = usec;
#else
*fsec = usec * 1.0e-6; *fsec = usec * 1.0e-6;
#endif
return; return;
} /* GetCurrentTimeUsec() */ } /* GetCurrentTimeUsec() */
...@@ -493,7 +476,7 @@ nabstimein(PG_FUNCTION_ARGS) ...@@ -493,7 +476,7 @@ nabstimein(PG_FUNCTION_ARGS)
{ {
char *str = PG_GETARG_CSTRING(0); char *str = PG_GETARG_CSTRING(0);
AbsoluteTime result; AbsoluteTime result;
double fsec; fsec_t fsec;
int tz = 0; int tz = 0;
struct tm date, struct tm date,
*tm = &date; *tm = &date;
...@@ -713,7 +696,7 @@ timestamp_abstime(PG_FUNCTION_ARGS) ...@@ -713,7 +696,7 @@ timestamp_abstime(PG_FUNCTION_ARGS)
{ {
Timestamp timestamp = PG_GETARG_TIMESTAMP(0); Timestamp timestamp = PG_GETARG_TIMESTAMP(0);
AbsoluteTime result; AbsoluteTime result;
double fsec; fsec_t fsec;
int tz; int tz;
struct tm tt, struct tm tt,
*tm = &tt; *tm = &tt;
...@@ -767,7 +750,9 @@ abstime_timestamp(PG_FUNCTION_ARGS) ...@@ -767,7 +750,9 @@ abstime_timestamp(PG_FUNCTION_ARGS)
default: default:
abstime2tm(abstime, &tz, tm, &tzn); abstime2tm(abstime, &tz, tm, &tzn);
result = abstime + ((date2j(1970, 1, 1) - date2j(2000, 1, 1)) * 86400) + tz; if (tm2timestamp(tm, 0, NULL, &result) != 0)
elog(ERROR, "Unable convert ABSTIME to TIMESTAMP"
"\n\tabstime_timestamp() internal error");
break; break;
}; };
...@@ -783,7 +768,7 @@ timestamptz_abstime(PG_FUNCTION_ARGS) ...@@ -783,7 +768,7 @@ timestamptz_abstime(PG_FUNCTION_ARGS)
{ {
TimestampTz timestamp = PG_GETARG_TIMESTAMP(0); TimestampTz timestamp = PG_GETARG_TIMESTAMP(0);
AbsoluteTime result; AbsoluteTime result;
double fsec; fsec_t fsec;
struct tm tt, struct tm tt,
*tm = &tt; *tm = &tt;
...@@ -810,6 +795,11 @@ abstime_timestamptz(PG_FUNCTION_ARGS) ...@@ -810,6 +795,11 @@ abstime_timestamptz(PG_FUNCTION_ARGS)
{ {
AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0); AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0);
TimestampTz result; TimestampTz result;
struct tm tt,
*tm = &tt;
int tz;
char zone[MAXDATELEN + 1],
*tzn = zone;
switch (abstime) switch (abstime)
{ {
...@@ -827,7 +817,10 @@ abstime_timestamptz(PG_FUNCTION_ARGS) ...@@ -827,7 +817,10 @@ abstime_timestamptz(PG_FUNCTION_ARGS)
break; break;
default: default:
result = abstime + ((date2j(1970, 1, 1) - date2j(2000, 1, 1)) * 86400); abstime2tm(abstime, &tz, tm, &tzn);
if (tm2timestamp(tm, 0, &tz, &result) != 0)
elog(ERROR, "Unable convert ABSTIME to TIMESTAMP WITH TIME ZONE"
"\n\tabstime_timestamp() internal error");
break; break;
}; };
...@@ -849,7 +842,7 @@ reltimein(PG_FUNCTION_ARGS) ...@@ -849,7 +842,7 @@ reltimein(PG_FUNCTION_ARGS)
RelativeTime result; RelativeTime result;
struct tm tt, struct tm tt,
*tm = &tt; *tm = &tt;
double fsec; fsec_t fsec;
int dtype; int dtype;
char *field[MAXDATEFIELDS]; char *field[MAXDATEFIELDS];
int nf, int nf,
...@@ -860,14 +853,14 @@ reltimein(PG_FUNCTION_ARGS) ...@@ -860,14 +853,14 @@ reltimein(PG_FUNCTION_ARGS)
elog(ERROR, "Bad (length) reltime external representation '%s'", str); elog(ERROR, "Bad (length) reltime external representation '%s'", str);
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0) if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateDelta(field, ftype, nf, &dtype, tm, &fsec) != 0)) || (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0))
elog(ERROR, "Bad reltime external representation '%s'", str); elog(ERROR, "Bad reltime external representation '%s'", str);
switch (dtype) switch (dtype)
{ {
case DTK_DELTA: case DTK_DELTA:
result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec); result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec);
result += (((tm->tm_year * 365) + (tm->tm_mon * 30) + tm->tm_mday) * (24 * 60 * 60)); result += ((tm->tm_year * 36525 * 864) + (((tm->tm_mon * 30) + tm->tm_mday) * 86400));
break; break;
default: default:
...@@ -893,7 +886,7 @@ reltimeout(PG_FUNCTION_ARGS) ...@@ -893,7 +886,7 @@ reltimeout(PG_FUNCTION_ARGS)
char buf[MAXDATELEN + 1]; char buf[MAXDATELEN + 1];
reltime2tm(time, tm); reltime2tm(time, tm);
EncodeTimeSpan(tm, 0, DateStyle, buf); EncodeInterval(tm, 0, DateStyle, buf);
result = pstrdup(buf); result = pstrdup(buf);
PG_RETURN_CSTRING(result); PG_RETURN_CSTRING(result);
...@@ -903,7 +896,7 @@ reltimeout(PG_FUNCTION_ARGS) ...@@ -903,7 +896,7 @@ reltimeout(PG_FUNCTION_ARGS)
static void static void
reltime2tm(RelativeTime time, struct tm * tm) reltime2tm(RelativeTime time, struct tm * tm)
{ {
TMODULO(time, tm->tm_year, 31536000); TMODULO(time, tm->tm_year, 31557600);
TMODULO(time, tm->tm_mon, 2592000); TMODULO(time, tm->tm_mon, 2592000);
TMODULO(time, tm->tm_mday, 86400); TMODULO(time, tm->tm_mday, 86400);
TMODULO(time, tm->tm_hour, 3600); TMODULO(time, tm->tm_hour, 3600);
...@@ -988,7 +981,11 @@ interval_reltime(PG_FUNCTION_ARGS) ...@@ -988,7 +981,11 @@ interval_reltime(PG_FUNCTION_ARGS)
RelativeTime time; RelativeTime time;
int year, int year,
month; month;
#ifdef HAVE_INT64_TIMESTAMP
int64 span;
#else
double span; double span;
#endif
if (interval->month == 0) if (interval->month == 0)
{ {
...@@ -1006,7 +1003,13 @@ interval_reltime(PG_FUNCTION_ARGS) ...@@ -1006,7 +1003,13 @@ interval_reltime(PG_FUNCTION_ARGS)
month = interval->month; month = interval->month;
} }
span = (((((double) 365 * year) + ((double) 30 * month)) * 86400) + interval->time); #ifdef HAVE_INT64_TIMESTAMP
span = ((((INT64CONST(365250000) * year) + (INT64CONST(30000000) * month))
* INT64CONST(86400)) + interval->time);
span /= INT64CONST(1000000);
#else
span = (((((double) 365.25 * year) + ((double) 30 * month)) * 86400) + interval->time);
#endif
if ((span < INT_MIN) || (span > INT_MAX)) if ((span < INT_MIN) || (span > INT_MAX))
time = INVALID_RELTIME; time = INVALID_RELTIME;
...@@ -1036,10 +1039,19 @@ reltime_interval(PG_FUNCTION_ARGS) ...@@ -1036,10 +1039,19 @@ reltime_interval(PG_FUNCTION_ARGS)
break; break;
default: default:
TMODULO(reltime, year, 31536000); #ifdef HAVE_INT64_TIMESTAMP
TMODULO(reltime, month, 2592000); year = (reltime / (36525 * 864));
reltime -= (year * (36525 * 864));
month = (reltime / (30 * 86400));
reltime -= (month * (30 * 86400));
result->time = (reltime * INT64CONST(1000000));
#else
TMODULO(reltime, year, (36525 * 864));
TMODULO(reltime, month, (30 * 86400));
result->time = reltime; result->time = reltime;
#endif
result->month = ((12 * year) + month); result->month = ((12 * year) + month);
break; break;
} }
...@@ -1090,11 +1102,6 @@ timepl(PG_FUNCTION_ARGS) ...@@ -1090,11 +1102,6 @@ timepl(PG_FUNCTION_ARGS)
AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0);
RelativeTime t2 = PG_GETARG_RELATIVETIME(1); RelativeTime t2 = PG_GETARG_RELATIVETIME(1);
#if 0
if (t1 == CURRENT_ABSTIME)
t1 = GetCurrentTransactionStartTime();
#endif
if (AbsoluteTimeIsReal(t1) && if (AbsoluteTimeIsReal(t1) &&
RelativeTimeIsValid(t2) && RelativeTimeIsValid(t2) &&
((t2 > 0) ? (t1 < NOEND_ABSTIME - t2) ((t2 > 0) ? (t1 < NOEND_ABSTIME - t2)
...@@ -1114,11 +1121,6 @@ timemi(PG_FUNCTION_ARGS) ...@@ -1114,11 +1121,6 @@ timemi(PG_FUNCTION_ARGS)
AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0);
RelativeTime t2 = PG_GETARG_RELATIVETIME(1); RelativeTime t2 = PG_GETARG_RELATIVETIME(1);
#if 0
if (t1 == CURRENT_ABSTIME)
t1 = GetCurrentTransactionStartTime();
#endif
if (AbsoluteTimeIsReal(t1) && if (AbsoluteTimeIsReal(t1) &&
RelativeTimeIsValid(t2) && RelativeTimeIsValid(t2) &&
((t2 > 0) ? (t1 > NOSTART_ABSTIME + t2) ((t2 > 0) ? (t1 > NOSTART_ABSTIME + t2)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.108 2002/04/16 23:08:11 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.109 2002/04/21 19:48:13 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2427,17 +2427,30 @@ convert_timevalue_to_scalar(Datum value, Oid typid) ...@@ -2427,17 +2427,30 @@ convert_timevalue_to_scalar(Datum value, Oid typid)
* assumed average month length of 365.25/12.0 days. Not * assumed average month length of 365.25/12.0 days. Not
* too accurate, but plenty good enough for our purposes. * too accurate, but plenty good enough for our purposes.
*/ */
#ifdef HAVE_INT64_TIMESTAMP
return (interval->time + (interval->month * ((365.25 / 12.0) * 86400000000.0)));
#else
return interval->time + return interval->time +
interval->month * (365.25 / 12.0 * 24.0 * 60.0 * 60.0); interval->month * (365.25 / 12.0 * 24.0 * 60.0 * 60.0);
#endif
} }
case RELTIMEOID: case RELTIMEOID:
#ifdef HAVE_INT64_TIMESTAMP
return (DatumGetRelativeTime(value) * 1000000.0);
#else
return DatumGetRelativeTime(value); return DatumGetRelativeTime(value);
#endif
case TINTERVALOID: case TINTERVALOID:
{ {
TimeInterval interval = DatumGetTimeInterval(value); TimeInterval interval = DatumGetTimeInterval(value);
#ifdef HAVE_INT64_TIMESTAMP
if (interval->status != 0)
return ((interval->data[1] - interval->data[0]) * 1000000.0);
#else
if (interval->status != 0) if (interval->status != 0)
return interval->data[1] - interval->data[0]; return interval->data[1] - interval->data[0];
#endif
return 0; /* for lack of a better idea */ return 0; /* for lack of a better idea */
} }
case TIMEOID: case TIMEOID:
...@@ -2447,7 +2460,11 @@ convert_timevalue_to_scalar(Datum value, Oid typid) ...@@ -2447,7 +2460,11 @@ convert_timevalue_to_scalar(Datum value, Oid typid)
TimeTzADT *timetz = DatumGetTimeTzADTP(value); TimeTzADT *timetz = DatumGetTimeTzADTP(value);
/* use GMT-equivalent time */ /* use GMT-equivalent time */
#ifdef HAVE_INT64_TIMESTAMP
return (double) (timetz->time + (timetz->zone * 1000000.0));
#else
return (double) (timetz->time + timetz->zone); return (double) (timetz->time + timetz->zone);
#endif
} }
} }
......
This diff is collapsed.
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: c.h,v 1.115 2002/03/29 17:32:55 petere Exp $ * $Id: c.h,v 1.116 2002/04/21 19:48:18 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -302,6 +302,10 @@ typedef unsigned long int uint64; ...@@ -302,6 +302,10 @@ typedef unsigned long int uint64;
#endif /* not HAVE_LONG_INT_64 and not HAVE_LONG_LONG_INT_64 */ #endif /* not HAVE_LONG_INT_64 and not HAVE_LONG_LONG_INT_64 */
#if defined(USE_INTEGER_DATETIMES) && !defined(INT64_IS_BUSTED)
#define HAVE_INT64_TIMESTAMP
#endif
/* sig_atomic_t is required by ANSI C, but may be missing on old platforms */ /* sig_atomic_t is required by ANSI C, but may be missing on old platforms */
#ifndef HAVE_SIG_ATOMIC_T #ifndef HAVE_SIG_ATOMIC_T
typedef int sig_atomic_t; typedef int sig_atomic_t;
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: catversion.h,v 1.121 2002/04/21 00:26:43 tgl Exp $ * $Id: catversion.h,v 1.122 2002/04/21 19:48:22 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -53,6 +53,6 @@ ...@@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 200204201 #define CATALOG_VERSION_NO 200204211
#endif #endif
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_control.h,v 1.6 2001/11/05 17:46:32 momjian Exp $ * $Id: pg_control.h,v 1.7 2002/04/21 19:48:23 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
/* Version identifier for this pg_control format */ /* Version identifier for this pg_control format */
#define PG_CONTROL_VERSION 71 #define PG_CONTROL_VERSION 72
/* /*
* Body of CheckPoint XLOG records. This is declared here because we keep * Body of CheckPoint XLOG records. This is declared here because we keep
...@@ -106,7 +106,15 @@ typedef struct ControlFileData ...@@ -106,7 +106,15 @@ typedef struct ControlFileData
*/ */
uint32 blcksz; /* block size for this DB */ uint32 blcksz; /* block size for this DB */
uint32 relseg_size; /* blocks per segment of large relation */ uint32 relseg_size; /* blocks per segment of large relation */
uint32 nameDataLen; /* catalog name field width */
uint32 funcMaxArgs; /* maximum number of function arguments */
/* flag indicating internal format of timestamp, interval, time */
uint32 enableIntTimes; /* int64 storage enabled? */
/* active locales --- "C" if compiled without USE_LOCALE: */ /* active locales --- "C" if compiled without USE_LOCALE: */
uint32 localeBuflen;
char lc_collate[LOCALE_NAME_BUFLEN]; char lc_collate[LOCALE_NAME_BUFLEN];
char lc_ctype[LOCALE_NAME_BUFLEN]; char lc_ctype[LOCALE_NAME_BUFLEN];
} ControlFileData; } ControlFileData;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_operator.h,v 1.102 2002/04/16 23:08:11 tgl Exp $ * $Id: pg_operator.h,v 1.103 2002/04/21 19:48:23 thomas Exp $
* *
* NOTES * NOTES
* the genbki.sh script reads this file and generates .bki * the genbki.sh script reads this file and generates .bki
...@@ -476,6 +476,8 @@ DATA(insert OID = 1068 ( ">" PGNSP PGUID 0 b t f 1043 1043 16 1066 1067 0 0 ...@@ -476,6 +476,8 @@ DATA(insert OID = 1068 ( ">" PGNSP PGUID 0 b t f 1043 1043 16 1066 1067 0 0
DATA(insert OID = 1069 ( ">=" PGNSP PGUID 0 b t f 1043 1043 16 1067 1066 0 0 0 0 varcharge scalargtsel scalargtjoinsel )); DATA(insert OID = 1069 ( ">=" PGNSP PGUID 0 b t f 1043 1043 16 1067 1066 0 0 0 0 varcharge scalargtsel scalargtjoinsel ));
/* date operators */ /* date operators */
DATA(insert OID = 1076 ( "+" PGNSP PGUID 0 b t f 1082 1186 1114 0 0 0 0 0 0 date_pl_interval - - ));
DATA(insert OID = 1077 ( "-" PGNSP PGUID 0 b t f 1082 1186 1114 0 0 0 0 0 0 date_mi_interval - - ));
DATA(insert OID = 1093 ( "=" PGNSP PGUID 0 b t t 1082 1082 16 1093 1094 1095 1095 1095 1097 date_eq eqsel eqjoinsel )); DATA(insert OID = 1093 ( "=" PGNSP PGUID 0 b t t 1082 1082 16 1093 1094 1095 1095 1095 1097 date_eq eqsel eqjoinsel ));
DATA(insert OID = 1094 ( "<>" PGNSP PGUID 0 b t f 1082 1082 16 1094 1093 0 0 0 0 date_ne neqsel neqjoinsel )); DATA(insert OID = 1094 ( "<>" PGNSP PGUID 0 b t f 1082 1082 16 1094 1093 0 0 0 0 date_ne neqsel neqjoinsel ));
DATA(insert OID = 1095 ( "<" PGNSP PGUID 0 b t f 1082 1082 16 1097 1098 0 0 0 0 date_lt scalarltsel scalarltjoinsel )); DATA(insert OID = 1095 ( "<" PGNSP PGUID 0 b t f 1082 1082 16 1097 1098 0 0 0 0 date_lt scalarltsel scalarltjoinsel ));
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_proc.h,v 1.228 2002/04/18 20:01:10 tgl Exp $ * $Id: pg_proc.h,v 1.229 2002/04/21 19:48:23 thomas Exp $
* *
* NOTES * NOTES
* The script catalog/genbki.sh reads this file and generates .bki * The script catalog/genbki.sh reads this file and generates .bki
...@@ -1280,7 +1280,7 @@ DESCR("convert timetz to text"); ...@@ -1280,7 +1280,7 @@ DESCR("convert timetz to text");
/* OIDS 1000 - 1999 */ /* OIDS 1000 - 1999 */
DATA(insert OID = 1026 ( timezone PGNSP PGUID 12 f t f t f s 2 25 "1186 1184" 100 0 0 100 timestamptz_izone - _null_ )); DATA(insert OID = 1026 ( timezone PGNSP PGUID 12 f t f t f s 2 1186 "1186 1184" 100 0 0 100 timestamptz_izone - _null_ ));
DESCR("time zone"); DESCR("time zone");
DATA(insert OID = 1029 ( nullvalue PGNSP PGUID 12 f t f f f i 1 16 "0" 100 0 0 100 nullvalue - _null_ )); DATA(insert OID = 1029 ( nullvalue PGNSP PGUID 12 f t f f f i 1 16 "0" 100 0 0 100 nullvalue - _null_ ));
...@@ -1414,8 +1414,8 @@ DATA(insert OID = 1156 ( timestamptz_ge PGNSP PGUID 12 f t f t f i 2 16 "1184 ...@@ -1414,8 +1414,8 @@ DATA(insert OID = 1156 ( timestamptz_ge PGNSP PGUID 12 f t f t f i 2 16 "1184
DESCR("greater-than-or-equal"); DESCR("greater-than-or-equal");
DATA(insert OID = 1157 ( timestamptz_gt PGNSP PGUID 12 f t f t f i 2 16 "1184 1184" 100 0 0 100 timestamp_gt - _null_ )); DATA(insert OID = 1157 ( timestamptz_gt PGNSP PGUID 12 f t f t f i 2 16 "1184 1184" 100 0 0 100 timestamp_gt - _null_ ));
DESCR("greater-than"); DESCR("greater-than");
DATA(insert OID = 1159 ( timezone PGNSP PGUID 12 f t f t f s 2 25 "25 1184" 100 0 0 100 timestamptz_zone - _null_ )); DATA(insert OID = 1159 ( timezone PGNSP PGUID 12 f t f t f s 2 1114 "25 1184" 100 0 0 100 timestamptz_zone - _null_ ));
DESCR("time zone"); DESCR("timestamp at a specified time zone");
DATA(insert OID = 1160 ( interval_in PGNSP PGUID 12 f t f t f s 1 1186 "0" 100 0 0 100 interval_in - _null_ )); DATA(insert OID = 1160 ( interval_in PGNSP PGUID 12 f t f t f s 1 1186 "0" 100 0 0 100 interval_in - _null_ ));
DESCR("(internal)"); DESCR("(internal)");
...@@ -1710,13 +1710,13 @@ DATA(insert OID = 1383 ( date_part PGNSP PGUID 14 f t f t f s 2 701 "25 703 ...@@ -1710,13 +1710,13 @@ DATA(insert OID = 1383 ( date_part PGNSP PGUID 14 f t f t f s 2 701 "25 703
DESCR("extract field from reltime"); DESCR("extract field from reltime");
DATA(insert OID = 1384 ( date_part PGNSP PGUID 14 f t f t f i 2 701 "25 1082" 100 0 0 100 "select date_part($1, cast($2 as timestamp without time zone))" - _null_ )); DATA(insert OID = 1384 ( date_part PGNSP PGUID 14 f t f t f i 2 701 "25 1082" 100 0 0 100 "select date_part($1, cast($2 as timestamp without time zone))" - _null_ ));
DESCR("extract field from date"); DESCR("extract field from date");
DATA(insert OID = 1385 ( date_part PGNSP PGUID 14 f t f t f i 2 701 "25 1083" 100 0 0 100 "select date_part($1, cast($2 as time with time zone))" - _null_ )); DATA(insert OID = 1385 ( date_part PGNSP PGUID 12 f t f t f i 2 701 "25 1083" 100 0 0 100 time_part - _null_ ));
DESCR("extract field from time"); DESCR("extract field from time");
DATA(insert OID = 1386 ( age PGNSP PGUID 14 f t f t f s 1 1186 "1184" 100 0 0 100 "select age(cast(current_date as timestamp with time zone), $1)" - _null_ )); DATA(insert OID = 1386 ( age PGNSP PGUID 14 f t f t f s 1 1186 "1184" 100 0 0 100 "select age(cast(current_date as timestamp with time zone), $1)" - _null_ ));
DESCR("date difference from today preserving months and years"); DESCR("date difference from today preserving months and years");
DATA(insert OID = 1388 ( timetz PGNSP PGUID 12 f t f t f s 1 1266 "1184" 100 0 0 100 timestamptz_timetz - _null_ )); DATA(insert OID = 1388 ( timetz PGNSP PGUID 12 f t f t f s 1 1266 "1184" 100 0 0 100 timestamptz_timetz - _null_ ));
DESCR("convert timestamp to timetz"); DESCR("convert timestamptz to timetz");
DATA(insert OID = 1389 ( isfinite PGNSP PGUID 12 f t f t f i 1 16 "1184" 100 0 0 100 timestamp_finite - _null_ )); DATA(insert OID = 1389 ( isfinite PGNSP PGUID 12 f t f t f i 1 16 "1184" 100 0 0 100 timestamp_finite - _null_ ));
DESCR("boolean test"); DESCR("boolean test");
...@@ -2769,6 +2769,8 @@ DESCR("return position of substring"); ...@@ -2769,6 +2769,8 @@ DESCR("return position of substring");
DATA(insert OID = 2015 ( btrim PGNSP PGUID 12 f t f t f i 2 17 "17 17" 100 0 0 100 byteatrim - _null_ )); DATA(insert OID = 2015 ( btrim PGNSP PGUID 12 f t f t f i 2 17 "17 17" 100 0 0 100 byteatrim - _null_ ));
DESCR("trim both ends of string"); DESCR("trim both ends of string");
DATA(insert OID = 2019 ( time PGNSP PGUID 12 f t f t f s 1 1083 "1184" 100 0 0 100 timestamptz_time - _null_ ));
DESCR("convert timestamptz to time");
DATA(insert OID = 2020 ( date_trunc PGNSP PGUID 12 f t f t f i 2 1114 "25 1114" 100 0 0 100 timestamp_trunc - _null_ )); DATA(insert OID = 2020 ( date_trunc PGNSP PGUID 12 f t f t f i 2 1114 "25 1114" 100 0 0 100 timestamp_trunc - _null_ ));
DESCR("truncate timestamp to specified units"); DESCR("truncate timestamp to specified units");
DATA(insert OID = 2021 ( date_part PGNSP PGUID 12 f t f t f i 2 701 "25 1114" 100 0 0 100 timestamp_part - _null_ )); DATA(insert OID = 2021 ( date_part PGNSP PGUID 12 f t f t f i 2 701 "25 1114" 100 0 0 100 timestamp_part - _null_ ));
...@@ -2801,9 +2803,9 @@ DATA(insert OID = 2035 ( timestamp_smaller PGNSP PGUID 12 f t f t f i 2 1114 "1 ...@@ -2801,9 +2803,9 @@ DATA(insert OID = 2035 ( timestamp_smaller PGNSP PGUID 12 f t f t f i 2 1114 "1
DESCR("smaller of two"); DESCR("smaller of two");
DATA(insert OID = 2036 ( timestamp_larger PGNSP PGUID 12 f t f t f i 2 1114 "1114 1114" 100 0 0 100 timestamp_larger - _null_ )); DATA(insert OID = 2036 ( timestamp_larger PGNSP PGUID 12 f t f t f i 2 1114 "1114 1114" 100 0 0 100 timestamp_larger - _null_ ));
DESCR("larger of two"); DESCR("larger of two");
DATA(insert OID = 2037 ( timetz PGNSP PGUID 12 f t f t f s 2 1266 "25 1266" 100 0 0 100 timetz_zone - _null_ )); DATA(insert OID = 2037 ( timezone PGNSP PGUID 12 f t f t f s 2 1266 "25 1266" 100 0 0 100 timetz_zone - _null_ ));
DESCR("time with time zone"); DESCR("time with time zone");
DATA(insert OID = 2038 ( timetz PGNSP PGUID 12 f t f t f i 2 1266 "1186 1266" 100 0 0 100 timetz_izone - _null_ )); DATA(insert OID = 2038 ( timezone PGNSP PGUID 12 f t f t f i 2 1266 "1186 1266" 100 0 0 100 timetz_izone - _null_ ));
DESCR("time with time zone"); DESCR("time with time zone");
DATA(insert OID = 2041 ( overlaps PGNSP PGUID 12 f t f f f i 4 16 "1114 1114 1114 1114" 100 0 0 100 overlaps_timestamp - _null_ )); DATA(insert OID = 2041 ( overlaps PGNSP PGUID 12 f t f f f i 4 16 "1114 1114 1114 1114" 100 0 0 100 overlaps_timestamp - _null_ ));
DESCR("SQL92 interval comparison"); DESCR("SQL92 interval comparison");
...@@ -2843,10 +2845,15 @@ DATA(insert OID = 2058 ( age PGNSP PGUID 12 f t f t f i 2 1186 "1114 1114" 1 ...@@ -2843,10 +2845,15 @@ DATA(insert OID = 2058 ( age PGNSP PGUID 12 f t f t f i 2 1186 "1114 1114" 1
DESCR("date difference preserving months and years"); DESCR("date difference preserving months and years");
DATA(insert OID = 2059 ( age PGNSP PGUID 14 f t f t f s 1 1186 "1114" 100 0 0 100 "select age(cast(current_date as timestamp without time zone), $1)" - _null_ )); DATA(insert OID = 2059 ( age PGNSP PGUID 14 f t f t f s 1 1186 "1114" 100 0 0 100 "select age(cast(current_date as timestamp without time zone), $1)" - _null_ ));
DESCR("date difference from today preserving months and years"); DESCR("date difference from today preserving months and years");
DATA(insert OID = 2069 ( timezone PGNSP PGUID 12 f t f t f s 2 1184 "25 1114" 100 0 0 100 timestamp_zone - _null_ )); DATA(insert OID = 2069 ( timezone PGNSP PGUID 12 f t f t f s 2 1184 "25 1114" 100 0 0 100 timestamp_zone - _null_ ));
DESCR("time zone"); DESCR("timestamp at a specified time zone");
DATA(insert OID = 2070 ( timezone PGNSP PGUID 12 f t f t f s 2 1184 "1186 1114" 100 0 0 100 timestamp_izone - _null_ )); DATA(insert OID = 2070 ( timezone PGNSP PGUID 12 f t f t f s 2 1184 "1186 1114" 100 0 0 100 timestamp_izone - _null_ ));
DESCR("time zone"); DESCR("time zone");
DATA(insert OID = 2071 ( date_pl_interval PGNSP PGUID 14 f t f t f i 2 1114 "1082 1186" 100 0 0 100 "select cast($1 as timestamp without time zone) + $2;" - _null_ ));
DESCR("add");
DATA(insert OID = 2072 ( date_mi_interval PGNSP PGUID 14 f t f t f i 2 1114 "1082 1186" 100 0 0 100 "select cast($1 as timestamp without time zone) - $2;" - _null_ ));
DESCR("subtract");
/* Aggregates (moved here from pg_aggregate for 7.3) */ /* Aggregates (moved here from pg_aggregate for 7.3) */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* or in pg_config.h afterwards. Of course, if you edit pg_config.h, then your * or in pg_config.h afterwards. Of course, if you edit pg_config.h, then your
* changes will be overwritten the next time you run configure. * changes will be overwritten the next time you run configure.
* *
* $Id: pg_config.h.in,v 1.22 2002/04/21 00:22:52 ishii Exp $ * $Id: pg_config.h.in,v 1.23 2002/04/21 19:48:19 thomas Exp $
*/ */
#ifndef PG_CONFIG_H #ifndef PG_CONFIG_H
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
/* A canonical string containing the version number, platform, and C compiler */ /* A canonical string containing the version number, platform, and C compiler */
#undef PG_VERSION_STR #undef PG_VERSION_STR
/* Set to 1 if you want 64-bit integer timestamp and interval support (--enable-integer-datetimes) */
#undef USE_INTEGER_DATETIMES
/* Set to 1 if you want cyrillic recode (--enable-recode) */ /* Set to 1 if you want cyrillic recode (--enable-recode) */
#undef CYR_RECODE #undef CYR_RECODE
......
...@@ -7,27 +7,41 @@ ...@@ -7,27 +7,41 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: date.h,v 1.17 2001/11/05 17:46:36 momjian Exp $ * $Id: date.h,v 1.18 2002/04/21 19:48:31 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef DATE_H #ifndef DATE_H
#define DATE_H #define DATE_H
#include "c.h"
#include "fmgr.h" #include "fmgr.h"
typedef int32 DateADT; typedef int32 DateADT;
#ifdef HAVE_INT64_TIMESTAMP
typedef int64 TimeADT;
#else
typedef float8 TimeADT; typedef float8 TimeADT;
#endif
typedef struct typedef struct
{ {
double time; /* all time units other than months and #ifdef HAVE_INT64_TIMESTAMP
* years */ int64 time; /* all time units other than months and years */
int32 zone; /* numeric time zone, in seconds */ #else
double time; /* all time units other than months and years */
#endif
int32 zone; /* numeric time zone, in seconds */
} TimeTzADT; } TimeTzADT;
#ifdef HAVE_INT64_TIMESTAMP
#define MAX_TIME_PRECISION 6
#else
#define MAX_TIME_PRECISION 13
#endif
/* /*
* Macros for fmgr-callable functions. * Macros for fmgr-callable functions.
* *
...@@ -90,6 +104,7 @@ extern Datum time_larger(PG_FUNCTION_ARGS); ...@@ -90,6 +104,7 @@ extern Datum time_larger(PG_FUNCTION_ARGS);
extern Datum time_smaller(PG_FUNCTION_ARGS); extern Datum time_smaller(PG_FUNCTION_ARGS);
extern Datum time_mi_time(PG_FUNCTION_ARGS); extern Datum time_mi_time(PG_FUNCTION_ARGS);
extern Datum timestamp_time(PG_FUNCTION_ARGS); extern Datum timestamp_time(PG_FUNCTION_ARGS);
extern Datum timestamptz_time(PG_FUNCTION_ARGS);
extern Datum time_interval(PG_FUNCTION_ARGS); extern Datum time_interval(PG_FUNCTION_ARGS);
extern Datum interval_time(PG_FUNCTION_ARGS); extern Datum interval_time(PG_FUNCTION_ARGS);
extern Datum text_time(PG_FUNCTION_ARGS); extern Datum text_time(PG_FUNCTION_ARGS);
...@@ -97,6 +112,7 @@ extern Datum time_text(PG_FUNCTION_ARGS); ...@@ -97,6 +112,7 @@ extern Datum time_text(PG_FUNCTION_ARGS);
extern Datum time_pl_interval(PG_FUNCTION_ARGS); extern Datum time_pl_interval(PG_FUNCTION_ARGS);
extern Datum time_mi_interval(PG_FUNCTION_ARGS); extern Datum time_mi_interval(PG_FUNCTION_ARGS);
extern Datum interval_pl_time(PG_FUNCTION_ARGS); extern Datum interval_pl_time(PG_FUNCTION_ARGS);
extern Datum time_part(PG_FUNCTION_ARGS);
extern Datum timetz_in(PG_FUNCTION_ARGS); extern Datum timetz_in(PG_FUNCTION_ARGS);
extern Datum timetz_out(PG_FUNCTION_ARGS); extern Datum timetz_out(PG_FUNCTION_ARGS);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: datetime.h,v 1.28 2002/01/01 02:54:33 thomas Exp $ * $Id: datetime.h,v 1.29 2002/04/21 19:48:31 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -198,15 +198,26 @@ typedef struct ...@@ -198,15 +198,26 @@ typedef struct
/* TMODULO() /* TMODULO()
* Macro to replace modf(), which is broken on some platforms. * Macro to replace modf(), which is broken on some platforms.
* t = input and remainder
* q = integer part
* u = divisor
*/ */
#ifdef HAVE_INT64_TIMESTAMP
#define TMODULO(t,q,u) \
do { \
q = (t / u); \
if (q != 0) t -= (q * u); \
} while(0)
#else
#define TMODULO(t,q,u) \ #define TMODULO(t,q,u) \
do { \ do { \
q = ((t < 0)? ceil(t / u): floor(t / u)); \ q = ((t < 0)? ceil(t / u): floor(t / u)); \
if (q != 0) \ if (q != 0) t -= rint(q * u); \
t -= rint(q * u); \
} while(0) } while(0)
#endif
#ifdef __CYGWIN__ /* Global variable holding time zone information. */
#if defined(__CYGWIN__) || defined(N_PLAT_NLM)
#define TIMEZONE_GLOBAL _timezone #define TIMEZONE_GLOBAL _timezone
#else #else
#define TIMEZONE_GLOBAL timezone #define TIMEZONE_GLOBAL timezone
...@@ -250,7 +261,7 @@ extern int day_tab[2][13]; ...@@ -250,7 +261,7 @@ extern int day_tab[2][13];
extern void GetCurrentTime(struct tm * tm); extern void GetCurrentTime(struct tm * tm);
extern void GetCurrentTimeUsec(struct tm * tm, double *fsec); extern void GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec);
extern void j2date(int jd, int *year, int *month, int *day); extern void j2date(int jd, int *year, int *month, int *day);
extern int date2j(int year, int month, int day); extern int date2j(int year, int month, int day);
...@@ -259,22 +270,22 @@ extern int ParseDateTime(char *timestr, char *lowstr, ...@@ -259,22 +270,22 @@ extern int ParseDateTime(char *timestr, char *lowstr,
int maxfields, int *numfields); int maxfields, int *numfields);
extern int DecodeDateTime(char **field, int *ftype, extern int DecodeDateTime(char **field, int *ftype,
int nf, int *dtype, int nf, int *dtype,
struct tm * tm, double *fsec, int *tzp); struct tm * tm, fsec_t *fsec, int *tzp);
extern int DecodeTimeOnly(char **field, int *ftype, extern int DecodeTimeOnly(char **field, int *ftype,
int nf, int *dtype, int nf, int *dtype,
struct tm * tm, double *fsec, int *tzp); struct tm * tm, fsec_t *fsec, int *tzp);
extern int DecodeDateDelta(char **field, int *ftype, extern int DecodeInterval(char **field, int *ftype,
int nf, int *dtype, int nf, int *dtype,
struct tm * tm, double *fsec); struct tm * tm, fsec_t *fsec);
extern int DetermineLocalTimeZone(struct tm * tm); extern int DetermineLocalTimeZone(struct tm * tm);
extern int EncodeDateOnly(struct tm * tm, int style, char *str); extern int EncodeDateOnly(struct tm * tm, int style, char *str);
extern int EncodeTimeOnly(struct tm * tm, double fsec, int *tzp, int style, char *str); extern int EncodeTimeOnly(struct tm * tm, fsec_t fsec, int *tzp, int style, char *str);
extern int EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, char *str); extern int EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, char *str);
extern int EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str); extern int EncodeInterval(struct tm * tm, fsec_t fsec, int style, char *str);
extern int DecodeSpecial(int field, char *lowtoken, int *val); extern int DecodeSpecial(int field, char *lowtoken, int *val);
extern int DecodeUnits(int field, char *lowtoken, int *val); extern int DecodeUnits(int field, char *lowtoken, int *val);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: int8.h,v 1.31 2001/11/05 17:46:36 momjian Exp $ * $Id: int8.h,v 1.32 2002/04/21 19:48:31 thomas Exp $
* *
* NOTES * NOTES
* These data types are supported on all 64-bit architectures, and may * These data types are supported on all 64-bit architectures, and may
...@@ -15,17 +15,25 @@ ...@@ -15,17 +15,25 @@
* is not currently supported, then please try to make it so, then post * is not currently supported, then please try to make it so, then post
* patches to the postgresql.org hackers mailing list. * patches to the postgresql.org hackers mailing list.
* *
* This code was written for and originally appeared in the contrib
* directory as a user-defined type.
* - thomas 1998-06-08
*
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef INT8_H #ifndef INT8_H
#define INT8_H #define INT8_H
#include "c.h"
#include "fmgr.h" #include "fmgr.h"
/* this should be set in pg_config.h, but just in case it wasn't: */
#ifndef INT64_FORMAT
#warning "Broken pg_config.h should have defined INT64_FORMAT"
#define INT64_FORMAT "%ld"
#endif
#ifdef HAVE_LL_CONSTANTS
#define INT64CONST(x) ((int64) x##LL)
#else
#define INT64CONST(x) ((int64) x)
#endif
extern Datum int8in(PG_FUNCTION_ARGS); extern Datum int8in(PG_FUNCTION_ARGS);
extern Datum int8out(PG_FUNCTION_ARGS); extern Datum int8out(PG_FUNCTION_ARGS);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: timestamp.h,v 1.24 2001/11/05 17:46:36 momjian Exp $ * $Id: timestamp.h,v 1.25 2002/04/21 19:48:31 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -18,8 +18,11 @@ ...@@ -18,8 +18,11 @@
#include <limits.h> #include <limits.h>
#include <float.h> #include <float.h>
#include "c.h"
#include "fmgr.h" #include "fmgr.h"
#ifdef HAVE_INT64_TIMESTAMP
#include "utils/int8.h"
#endif
/* /*
* Timestamp represents absolute time. * Timestamp represents absolute time.
...@@ -31,16 +34,22 @@ ...@@ -31,16 +34,22 @@
* consisting of a beginning and ending time, not a time span - thomas 97/03/20 * consisting of a beginning and ending time, not a time span - thomas 97/03/20
*/ */
#ifdef HAVE_INT64_TIMESTAMP
typedef int64 Timestamp;
typedef int64 TimestampTz;
#else
typedef double Timestamp; typedef double Timestamp;
typedef double TimestampTz; typedef double TimestampTz;
#endif
typedef struct typedef struct
{ {
double time; /* all time units other than months and #ifdef HAVE_INT64_TIMESTAMP
* years */ int64 time; /* all time units other than months and years */
int32 month; /* months and years, after time for #else
* alignment */ double time; /* all time units other than months and years */
#endif
int32 month; /* months and years, after time for alignment */
} Interval; } Interval;
...@@ -50,6 +59,27 @@ typedef struct ...@@ -50,6 +59,27 @@ typedef struct
* For Timestamp, we make use of the same support routines as for float8. * For Timestamp, we make use of the same support routines as for float8.
* Therefore Timestamp is pass-by-reference if and only if float8 is! * Therefore Timestamp is pass-by-reference if and only if float8 is!
*/ */
#ifdef HAVE_INT64_TIMESTAMP
#define DatumGetTimestamp(X) ((Timestamp) DatumGetInt64(X))
#define DatumGetTimestampTz(X) ((TimestampTz) DatumGetInt64(X))
#define DatumGetIntervalP(X) ((Interval *) DatumGetPointer(X))
#define TimestampGetDatum(X) Int64GetDatum(X)
#define TimestampTzGetDatum(X) Int64GetDatum(X)
#define IntervalPGetDatum(X) PointerGetDatum(X)
#define PG_GETARG_TIMESTAMP(n) PG_GETARG_INT64(n)
#define PG_GETARG_TIMESTAMPTZ(n) PG_GETARG_INT64(n)
#define PG_GETARG_INTERVAL_P(n) DatumGetIntervalP(PG_GETARG_DATUM(n))
#define PG_RETURN_TIMESTAMP(x) PG_RETURN_INT64(x)
#define PG_RETURN_TIMESTAMPTZ(x) PG_RETURN_INT64(x)
#define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x)
#define DT_NOBEGIN (-INT64CONST(0x7fffffffffffffff) - 1)
#define DT_NOEND (INT64CONST(0x7fffffffffffffff))
#else
#define DatumGetTimestamp(X) ((Timestamp) DatumGetFloat8(X)) #define DatumGetTimestamp(X) ((Timestamp) DatumGetFloat8(X))
#define DatumGetTimestampTz(X) ((TimestampTz) DatumGetFloat8(X)) #define DatumGetTimestampTz(X) ((TimestampTz) DatumGetFloat8(X))
#define DatumGetIntervalP(X) ((Interval *) DatumGetPointer(X)) #define DatumGetIntervalP(X) ((Interval *) DatumGetPointer(X))
...@@ -66,7 +96,6 @@ typedef struct ...@@ -66,7 +96,6 @@ typedef struct
#define PG_RETURN_TIMESTAMPTZ(x) return TimestampTzGetDatum(x) #define PG_RETURN_TIMESTAMPTZ(x) return TimestampTzGetDatum(x)
#define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x) #define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x)
#ifdef HUGE_VAL #ifdef HUGE_VAL
#define DT_NOBEGIN (-HUGE_VAL) #define DT_NOBEGIN (-HUGE_VAL)
#define DT_NOEND (HUGE_VAL) #define DT_NOEND (HUGE_VAL)
...@@ -74,6 +103,7 @@ typedef struct ...@@ -74,6 +103,7 @@ typedef struct
#define DT_NOBEGIN (-DBL_MAX) #define DT_NOBEGIN (-DBL_MAX)
#define DT_NOEND (DBL_MAX) #define DT_NOEND (DBL_MAX)
#endif #endif
#endif
#define TIMESTAMP_NOBEGIN(j) do {j = DT_NOBEGIN;} while (0) #define TIMESTAMP_NOBEGIN(j) do {j = DT_NOBEGIN;} while (0)
#define TIMESTAMP_IS_NOBEGIN(j) ((j) == DT_NOBEGIN) #define TIMESTAMP_IS_NOBEGIN(j) ((j) == DT_NOBEGIN)
...@@ -83,8 +113,21 @@ typedef struct ...@@ -83,8 +113,21 @@ typedef struct
#define TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) || TIMESTAMP_IS_NOEND(j)) #define TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) || TIMESTAMP_IS_NOEND(j))
#define MAX_TIMESTAMP_PRECISION 6
#define MAX_INTERVAL_PRECISION 6
#ifdef HAVE_INT64_TIMESTAMP
typedef int32 fsec_t;
#define SECONDS_TO_TIMESTAMP(x) (INT64CONST(x000000))
#else
typedef double fsec_t;
#define SECONDS_TO_TIMESTAMP(x) (xe0)
#define TIME_PREC_INV 1000000.0 #define TIME_PREC_INV 1000000.0
#define JROUND(j) (rint(((double) (j))*TIME_PREC_INV)/TIME_PREC_INV) #define JROUND(j) (rint(((double) (j))*TIME_PREC_INV)/TIME_PREC_INV)
#endif
/* /*
...@@ -167,13 +210,13 @@ extern Datum now(PG_FUNCTION_ARGS); ...@@ -167,13 +210,13 @@ extern Datum now(PG_FUNCTION_ARGS);
/* Internal routines (not fmgr-callable) */ /* Internal routines (not fmgr-callable) */
extern int tm2timestamp(struct tm * tm, double fsec, int *tzp, Timestamp *dt); extern int tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp *dt);
extern int timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, extern int timestamp2tm(Timestamp dt, int *tzp, struct tm * tm,
double *fsec, char **tzn); fsec_t *fsec, char **tzn);
extern void dt2time(Timestamp dt, int *hour, int *min, double *sec); extern void dt2time(Timestamp dt, int *hour, int *min, int *sec, fsec_t *fsec);
extern int interval2tm(Interval span, struct tm * tm, float8 *fsec); extern int interval2tm(Interval span, struct tm * tm, fsec_t *fsec);
extern int tm2interval(struct tm * tm, double fsec, Interval *span); extern int tm2interval(struct tm * tm, fsec_t fsec, Interval *span);
extern Timestamp SetEpochTimestamp(void); extern Timestamp SetEpochTimestamp(void);
extern void GetEpochTime(struct tm * tm); extern void GetEpochTime(struct tm * tm);
......
...@@ -264,22 +264,22 @@ SELECT date '2001-02-03' + time with time zone '04:05:06 UTC' AS "Date + Time UT ...@@ -264,22 +264,22 @@ SELECT date '2001-02-03' + time with time zone '04:05:06 UTC' AS "Date + Time UT
(1 row) (1 row)
SELECT date '1991-02-03' + interval '2 years' AS "Add Two Years"; SELECT date '1991-02-03' + interval '2 years' AS "Add Two Years";
Add Two Years Add Two Years
------------------------------ --------------------------
Wed Feb 03 00:00:00 1993 PST Wed Feb 03 00:00:00 1993
(1 row) (1 row)
SELECT date '2001-12-13' - interval '2 years' AS "Subtract Two Years"; SELECT date '2001-12-13' - interval '2 years' AS "Subtract Two Years";
Subtract Two Years Subtract Two Years
------------------------------ --------------------------
Mon Dec 13 00:00:00 1999 PST Mon Dec 13 00:00:00 1999
(1 row) (1 row)
-- subtract time from date should not make sense; use interval instead -- subtract time from date should not make sense; use interval instead
SELECT date '1991-02-03' - time '04:05:06' AS "Subtract Time"; SELECT date '1991-02-03' - time '04:05:06' AS "Subtract Time";
Subtract Time Subtract Time
------------------------------ --------------------------
Sat Feb 02 19:54:54 1991 PST Sat Feb 02 19:54:54 1991
(1 row) (1 row)
SELECT date '1991-02-03' - time with time zone '04:05:06 UTC' AS "Subtract Time UTC"; SELECT date '1991-02-03' - time with time zone '04:05:06 UTC' AS "Subtract Time UTC";
...@@ -406,7 +406,7 @@ SELECT '' AS "64", d1 + interval '1 year' AS one_year FROM TIMESTAMP_TBL; ...@@ -406,7 +406,7 @@ SELECT '' AS "64", d1 + interval '1 year' AS one_year FROM TIMESTAMP_TBL;
| Sat Feb 14 17:32:01 1998 | Sat Feb 14 17:32:01 1998
| Sun Feb 15 17:32:01 1998 | Sun Feb 15 17:32:01 1998
| Mon Feb 16 17:32:01 1998 | Mon Feb 16 17:32:01 1998
| Thu Feb 16 17:32 0096 BC | Thu Feb 16 17:32:01 0096 BC
| Sun Feb 16 17:32:01 0098 | Sun Feb 16 17:32:01 0098
| Fri Feb 16 17:32:01 0598 | Fri Feb 16 17:32:01 0598
| Wed Feb 16 17:32:01 1098 | Wed Feb 16 17:32:01 1098
...@@ -475,7 +475,7 @@ SELECT '' AS "64", d1 - interval '1 year' AS one_year FROM TIMESTAMP_TBL; ...@@ -475,7 +475,7 @@ SELECT '' AS "64", d1 - interval '1 year' AS one_year FROM TIMESTAMP_TBL;
| Wed Feb 14 17:32:01 1996 | Wed Feb 14 17:32:01 1996
| Thu Feb 15 17:32:01 1996 | Thu Feb 15 17:32:01 1996
| Fri Feb 16 17:32:01 1996 | Fri Feb 16 17:32:01 1996
| Mon Feb 16 17:32 0098 BC | Mon Feb 16 17:32:01 0098 BC
| Thu Feb 16 17:32:01 0096 | Thu Feb 16 17:32:01 0096
| Tue Feb 16 17:32:01 0596 | Tue Feb 16 17:32:01 0596
| Sun Feb 16 17:32:01 1096 | Sun Feb 16 17:32:01 1096
...@@ -622,7 +622,7 @@ SELECT '' AS "64", d1 + interval '1 year' AS one_year FROM TIMESTAMPTZ_TBL; ...@@ -622,7 +622,7 @@ SELECT '' AS "64", d1 + interval '1 year' AS one_year FROM TIMESTAMPTZ_TBL;
| Sat Feb 14 17:32:01 1998 PST | Sat Feb 14 17:32:01 1998 PST
| Sun Feb 15 17:32:01 1998 PST | Sun Feb 15 17:32:01 1998 PST
| Mon Feb 16 17:32:01 1998 PST | Mon Feb 16 17:32:01 1998 PST
| Thu Feb 16 17:32 0096 BC | Thu Feb 16 17:32:01 0096 BC
| Sun Feb 16 17:32:01 0098 | Sun Feb 16 17:32:01 0098
| Fri Feb 16 17:32:01 0598 | Fri Feb 16 17:32:01 0598
| Wed Feb 16 17:32:01 1098 | Wed Feb 16 17:32:01 1098
...@@ -691,7 +691,7 @@ SELECT '' AS "64", d1 - interval '1 year' AS one_year FROM TIMESTAMPTZ_TBL; ...@@ -691,7 +691,7 @@ SELECT '' AS "64", d1 - interval '1 year' AS one_year FROM TIMESTAMPTZ_TBL;
| Wed Feb 14 17:32:01 1996 PST | Wed Feb 14 17:32:01 1996 PST
| Thu Feb 15 17:32:01 1996 PST | Thu Feb 15 17:32:01 1996 PST
| Fri Feb 16 17:32:01 1996 PST | Fri Feb 16 17:32:01 1996 PST
| Mon Feb 16 17:32 0098 BC | Mon Feb 16 17:32:01 0098 BC
| Thu Feb 16 17:32:01 0096 | Thu Feb 16 17:32:01 0096
| Tue Feb 16 17:32:01 0596 | Tue Feb 16 17:32:01 0596
| Sun Feb 16 17:32:01 1096 | Sun Feb 16 17:32:01 1096
...@@ -1519,7 +1519,7 @@ SELECT (time '00:00', interval '1 hour') ...@@ -1519,7 +1519,7 @@ SELECT (time '00:00', interval '1 hour')
f f
(1 row) (1 row)
CREATE TABLE TEMP_TIMESTAMP (f1 timestamp); CREATE TABLE TEMP_TIMESTAMP (f1 timestamp with time zone);
-- get some candidate input values -- get some candidate input values
INSERT INTO TEMP_TIMESTAMP (f1) INSERT INTO TEMP_TIMESTAMP (f1)
SELECT d1 FROM TIMESTAMP_TBL SELECT d1 FROM TIMESTAMP_TBL
...@@ -1883,8 +1883,9 @@ SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS "interval", d.f1 - t.f1 AS minu ...@@ -1883,8 +1883,9 @@ SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS "interval", d.f1 - t.f1 AS minu
| Sat Sep 22 18:19:20 2001 PDT | @ 14 secs ago | Sat Sep 22 18:19:34 2001 PDT | Sat Sep 22 18:19:20 2001 PDT | @ 14 secs ago | Sat Sep 22 18:19:34 2001 PDT
(160 rows) (160 rows)
SELECT '' AS "16", d.f1 AS "timestamp", timestamp '1980-01-06 00:00 GMT' AS gpstime_zero, SELECT '' AS "16", d.f1 AS "timestamp",
d.f1 - timestamp '1980-01-06 00:00 GMT' AS difference timestamp with time zone '1980-01-06 00:00 GMT' AS gpstime_zero,
d.f1 - timestamp with time zone '1980-01-06 00:00 GMT' AS difference
FROM TEMP_TIMESTAMP d FROM TEMP_TIMESTAMP d
ORDER BY difference; ORDER BY difference;
16 | timestamp | gpstime_zero | difference 16 | timestamp | gpstime_zero | difference
...@@ -2305,7 +2306,7 @@ SELECT '' AS two, d1 AS "timestamp", abstime(d1) AS abstime ...@@ -2305,7 +2306,7 @@ SELECT '' AS two, d1 AS "timestamp", abstime(d1) AS abstime
SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp" SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp"
FROM ABSTIME_TBL WHERE NOT isfinite(f1); FROM ABSTIME_TBL WHERE NOT isfinite(f1);
ERROR: Unable to convert abstime 'invalid' to timestamptz ERROR: Unable to convert abstime 'invalid' to timestamp
SELECT '' AS ten, f1 AS interval, reltime(f1) AS reltime SELECT '' AS ten, f1 AS interval, reltime(f1) AS reltime
FROM INTERVAL_TBL; FROM INTERVAL_TBL;
ten | interval | reltime ten | interval | reltime
...@@ -2385,7 +2386,7 @@ SELECT '' AS "64", d1 AS us_postgres FROM TIMESTAMP_TBL; ...@@ -2385,7 +2386,7 @@ SELECT '' AS "64", d1 AS us_postgres FROM TIMESTAMP_TBL;
| Fri Feb 14 17:32:01 1997 | Fri Feb 14 17:32:01 1997
| Sat Feb 15 17:32:01 1997 | Sat Feb 15 17:32:01 1997
| Sun Feb 16 17:32:01 1997 | Sun Feb 16 17:32:01 1997
| Tue Feb 16 17:32 0097 BC | Tue Feb 16 17:32:01 0097 BC
| Sat Feb 16 17:32:01 0097 | Sat Feb 16 17:32:01 0097
| Thu Feb 16 17:32:01 0597 | Thu Feb 16 17:32:01 0597
| Tue Feb 16 17:32:01 1097 | Tue Feb 16 17:32:01 1097
...@@ -2467,7 +2468,7 @@ SELECT '' AS "64", d1 AS us_iso FROM TIMESTAMP_TBL; ...@@ -2467,7 +2468,7 @@ SELECT '' AS "64", d1 AS us_iso FROM TIMESTAMP_TBL;
| 1997-02-14 17:32:01 | 1997-02-14 17:32:01
| 1997-02-15 17:32:01 | 1997-02-15 17:32:01
| 1997-02-16 17:32:01 | 1997-02-16 17:32:01
| 0097-02-16 17:32 BC | 0097-02-16 17:32:01 BC
| 0097-02-16 17:32:01 | 0097-02-16 17:32:01
| 0597-02-16 17:32:01 | 0597-02-16 17:32:01
| 1097-02-16 17:32:01 | 1097-02-16 17:32:01
...@@ -2551,7 +2552,7 @@ SELECT '' AS "64", d1 AS us_sql FROM TIMESTAMP_TBL; ...@@ -2551,7 +2552,7 @@ SELECT '' AS "64", d1 AS us_sql FROM TIMESTAMP_TBL;
| 02/14/1997 17:32:01 | 02/14/1997 17:32:01
| 02/15/1997 17:32:01 | 02/15/1997 17:32:01
| 02/16/1997 17:32:01 | 02/16/1997 17:32:01
| 02/16/0097 17:32 BC | 02/16/0097 17:32:01 BC
| 02/16/0097 17:32:01 | 02/16/0097 17:32:01
| 02/16/0597 17:32:01 | 02/16/0597 17:32:01
| 02/16/1097 17:32:01 | 02/16/1097 17:32:01
...@@ -2642,7 +2643,7 @@ SELECT '' AS "65", d1 AS european_postgres FROM TIMESTAMP_TBL; ...@@ -2642,7 +2643,7 @@ SELECT '' AS "65", d1 AS european_postgres FROM TIMESTAMP_TBL;
| Fri 14 Feb 17:32:01 1997 | Fri 14 Feb 17:32:01 1997
| Sat 15 Feb 17:32:01 1997 | Sat 15 Feb 17:32:01 1997
| Sun 16 Feb 17:32:01 1997 | Sun 16 Feb 17:32:01 1997
| Tue 16 Feb 17:32 0097 BC | Tue 16 Feb 17:32:01 0097 BC
| Sat 16 Feb 17:32:01 0097 | Sat 16 Feb 17:32:01 0097
| Thu 16 Feb 17:32:01 0597 | Thu 16 Feb 17:32:01 0597
| Tue 16 Feb 17:32:01 1097 | Tue 16 Feb 17:32:01 1097
...@@ -2727,7 +2728,7 @@ SELECT '' AS "65", d1 AS european_iso FROM TIMESTAMP_TBL; ...@@ -2727,7 +2728,7 @@ SELECT '' AS "65", d1 AS european_iso FROM TIMESTAMP_TBL;
| 1997-02-14 17:32:01 | 1997-02-14 17:32:01
| 1997-02-15 17:32:01 | 1997-02-15 17:32:01
| 1997-02-16 17:32:01 | 1997-02-16 17:32:01
| 0097-02-16 17:32 BC | 0097-02-16 17:32:01 BC
| 0097-02-16 17:32:01 | 0097-02-16 17:32:01
| 0597-02-16 17:32:01 | 0597-02-16 17:32:01
| 1097-02-16 17:32:01 | 1097-02-16 17:32:01
...@@ -2812,7 +2813,7 @@ SELECT '' AS "65", d1 AS european_sql FROM TIMESTAMP_TBL; ...@@ -2812,7 +2813,7 @@ SELECT '' AS "65", d1 AS european_sql FROM TIMESTAMP_TBL;
| 14/02/1997 17:32:01 | 14/02/1997 17:32:01
| 15/02/1997 17:32:01 | 15/02/1997 17:32:01
| 16/02/1997 17:32:01 | 16/02/1997 17:32:01
| 16/02/0097 17:32 BC | 16/02/0097 17:32:01 BC
| 16/02/0097 17:32:01 | 16/02/0097 17:32:01
| 16/02/0597 17:32:01 | 16/02/0597 17:32:01
| 16/02/1097 17:32:01 | 16/02/1097 17:32:01
......
...@@ -183,7 +183,7 @@ SELECT '' AS "64", d1 FROM TIMESTAMP_TBL; ...@@ -183,7 +183,7 @@ SELECT '' AS "64", d1 FROM TIMESTAMP_TBL;
| Fri Feb 14 17:32:01 1997 | Fri Feb 14 17:32:01 1997
| Sat Feb 15 17:32:01 1997 | Sat Feb 15 17:32:01 1997
| Sun Feb 16 17:32:01 1997 | Sun Feb 16 17:32:01 1997
| Tue Feb 16 17:32 0097 BC | Tue Feb 16 17:32:01 0097 BC
| Sat Feb 16 17:32:01 0097 | Sat Feb 16 17:32:01 0097
| Thu Feb 16 17:32:01 0597 | Thu Feb 16 17:32:01 0597
| Tue Feb 16 17:32:01 1097 | Tue Feb 16 17:32:01 1097
...@@ -265,11 +265,11 @@ SELECT '' AS "48", d1 FROM TIMESTAMP_TBL ...@@ -265,11 +265,11 @@ SELECT '' AS "48", d1 FROM TIMESTAMP_TBL
SELECT '' AS "15", d1 FROM TIMESTAMP_TBL SELECT '' AS "15", d1 FROM TIMESTAMP_TBL
WHERE d1 < timestamp without time zone '1997-01-02'; WHERE d1 < timestamp without time zone '1997-01-02';
15 | d1 15 | d1
----+-------------------------- ----+-----------------------------
| -infinity | -infinity
| Thu Jan 01 00:00:00 1970 | Thu Jan 01 00:00:00 1970
| Tue Feb 16 17:32 0097 BC | Tue Feb 16 17:32:01 0097 BC
| Sat Feb 16 17:32:01 0097 | Sat Feb 16 17:32:01 0097
| Thu Feb 16 17:32:01 0597 | Thu Feb 16 17:32:01 0597
| Tue Feb 16 17:32:01 1097 | Tue Feb 16 17:32:01 1097
...@@ -335,7 +335,7 @@ SELECT '' AS "63", d1 FROM TIMESTAMP_TBL ...@@ -335,7 +335,7 @@ SELECT '' AS "63", d1 FROM TIMESTAMP_TBL
| Fri Feb 14 17:32:01 1997 | Fri Feb 14 17:32:01 1997
| Sat Feb 15 17:32:01 1997 | Sat Feb 15 17:32:01 1997
| Sun Feb 16 17:32:01 1997 | Sun Feb 16 17:32:01 1997
| Tue Feb 16 17:32 0097 BC | Tue Feb 16 17:32:01 0097 BC
| Sat Feb 16 17:32:01 0097 | Sat Feb 16 17:32:01 0097
| Thu Feb 16 17:32:01 0597 | Thu Feb 16 17:32:01 0597
| Tue Feb 16 17:32:01 1097 | Tue Feb 16 17:32:01 1097
...@@ -362,12 +362,12 @@ SELECT '' AS "63", d1 FROM TIMESTAMP_TBL ...@@ -362,12 +362,12 @@ SELECT '' AS "63", d1 FROM TIMESTAMP_TBL
SELECT '' AS "16", d1 FROM TIMESTAMP_TBL SELECT '' AS "16", d1 FROM TIMESTAMP_TBL
WHERE d1 <= timestamp without time zone '1997-01-02'; WHERE d1 <= timestamp without time zone '1997-01-02';
16 | d1 16 | d1
----+-------------------------- ----+-----------------------------
| -infinity | -infinity
| Thu Jan 01 00:00:00 1970 | Thu Jan 01 00:00:00 1970
| Thu Jan 02 00:00:00 1997 | Thu Jan 02 00:00:00 1997
| Tue Feb 16 17:32 0097 BC | Tue Feb 16 17:32:01 0097 BC
| Sat Feb 16 17:32:01 0097 | Sat Feb 16 17:32:01 0097
| Thu Feb 16 17:32:01 0597 | Thu Feb 16 17:32:01 0597
| Tue Feb 16 17:32:01 1097 | Tue Feb 16 17:32:01 1097
......
...@@ -178,7 +178,7 @@ SELECT '' AS "64", d1 FROM TIMESTAMPTZ_TBL; ...@@ -178,7 +178,7 @@ SELECT '' AS "64", d1 FROM TIMESTAMPTZ_TBL;
| Fri Feb 14 17:32:01 1997 PST | Fri Feb 14 17:32:01 1997 PST
| Sat Feb 15 17:32:01 1997 PST | Sat Feb 15 17:32:01 1997 PST
| Sun Feb 16 17:32:01 1997 PST | Sun Feb 16 17:32:01 1997 PST
| Tue Feb 16 17:32 0097 BC | Tue Feb 16 17:32:01 0097 BC
| Sat Feb 16 17:32:01 0097 | Sat Feb 16 17:32:01 0097
| Thu Feb 16 17:32:01 0597 | Thu Feb 16 17:32:01 0597
| Tue Feb 16 17:32:01 1097 | Tue Feb 16 17:32:01 1097
...@@ -264,7 +264,7 @@ SELECT '' AS "15", d1 FROM TIMESTAMPTZ_TBL ...@@ -264,7 +264,7 @@ SELECT '' AS "15", d1 FROM TIMESTAMPTZ_TBL
----+------------------------------ ----+------------------------------
| -infinity | -infinity
| Wed Dec 31 16:00:00 1969 PST | Wed Dec 31 16:00:00 1969 PST
| Tue Feb 16 17:32 0097 BC | Tue Feb 16 17:32:01 0097 BC
| Sat Feb 16 17:32:01 0097 | Sat Feb 16 17:32:01 0097
| Thu Feb 16 17:32:01 0597 | Thu Feb 16 17:32:01 0597
| Tue Feb 16 17:32:01 1097 | Tue Feb 16 17:32:01 1097
...@@ -330,7 +330,7 @@ SELECT '' AS "63", d1 FROM TIMESTAMPTZ_TBL ...@@ -330,7 +330,7 @@ SELECT '' AS "63", d1 FROM TIMESTAMPTZ_TBL
| Fri Feb 14 17:32:01 1997 PST | Fri Feb 14 17:32:01 1997 PST
| Sat Feb 15 17:32:01 1997 PST | Sat Feb 15 17:32:01 1997 PST
| Sun Feb 16 17:32:01 1997 PST | Sun Feb 16 17:32:01 1997 PST
| Tue Feb 16 17:32 0097 BC | Tue Feb 16 17:32:01 0097 BC
| Sat Feb 16 17:32:01 0097 | Sat Feb 16 17:32:01 0097
| Thu Feb 16 17:32:01 0597 | Thu Feb 16 17:32:01 0597
| Tue Feb 16 17:32:01 1097 | Tue Feb 16 17:32:01 1097
...@@ -362,7 +362,7 @@ SELECT '' AS "16", d1 FROM TIMESTAMPTZ_TBL ...@@ -362,7 +362,7 @@ SELECT '' AS "16", d1 FROM TIMESTAMPTZ_TBL
| -infinity | -infinity
| Wed Dec 31 16:00:00 1969 PST | Wed Dec 31 16:00:00 1969 PST
| Thu Jan 02 00:00:00 1997 PST | Thu Jan 02 00:00:00 1997 PST
| Tue Feb 16 17:32 0097 BC | Tue Feb 16 17:32:01 0097 BC
| Sat Feb 16 17:32:01 0097 | Sat Feb 16 17:32:01 0097
| Thu Feb 16 17:32:01 0597 | Thu Feb 16 17:32:01 0597
| Tue Feb 16 17:32:01 1097 | Tue Feb 16 17:32:01 1097
......
...@@ -214,7 +214,7 @@ SELECT (time '00:00', interval '1 hour') ...@@ -214,7 +214,7 @@ SELECT (time '00:00', interval '1 hour')
SELECT (time '00:00', interval '1 hour') SELECT (time '00:00', interval '1 hour')
OVERLAPS (time '01:30', interval '1 day') AS "False"; OVERLAPS (time '01:30', interval '1 day') AS "False";
CREATE TABLE TEMP_TIMESTAMP (f1 timestamp); CREATE TABLE TEMP_TIMESTAMP (f1 timestamp with time zone);
-- get some candidate input values -- get some candidate input values
...@@ -236,8 +236,9 @@ SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS "interval", d.f1 - t.f1 AS minu ...@@ -236,8 +236,9 @@ SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS "interval", d.f1 - t.f1 AS minu
WHERE isfinite(d.f1) WHERE isfinite(d.f1)
ORDER BY minus, "timestamp", "interval"; ORDER BY minus, "timestamp", "interval";
SELECT '' AS "16", d.f1 AS "timestamp", timestamp '1980-01-06 00:00 GMT' AS gpstime_zero, SELECT '' AS "16", d.f1 AS "timestamp",
d.f1 - timestamp '1980-01-06 00:00 GMT' AS difference timestamp with time zone '1980-01-06 00:00 GMT' AS gpstime_zero,
d.f1 - timestamp with time zone '1980-01-06 00:00 GMT' AS difference
FROM TEMP_TIMESTAMP d FROM TEMP_TIMESTAMP d
ORDER BY difference; ORDER BY difference;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment