Commit 9dbd00b0 authored by Bruce Momjian's avatar Bruce Momjian

Remove unnecessary parentheses in assignments.

Add spaces where needed.
Reference time interval variables as tinterval.
parent 3976899f
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.119 2005/07/14 21:46:30 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.120 2005/07/21 04:41:42 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1017,7 +1017,7 @@ aclmask(const Acl *acl, Oid roleid, Oid ownerId, ...@@ -1017,7 +1017,7 @@ aclmask(const Acl *acl, Oid roleid, Oid ownerId,
if (aidata->ai_grantee == ACL_ID_PUBLIC || if (aidata->ai_grantee == ACL_ID_PUBLIC ||
aidata->ai_grantee == roleid) aidata->ai_grantee == roleid)
{ {
result |= (aidata->ai_privs & mask); result |= aidata->ai_privs & mask;
if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0)) if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
return result; return result;
} }
...@@ -1030,7 +1030,7 @@ aclmask(const Acl *acl, Oid roleid, Oid ownerId, ...@@ -1030,7 +1030,7 @@ aclmask(const Acl *acl, Oid roleid, Oid ownerId,
* a given ACL entry grants any privileges still of interest before * a given ACL entry grants any privileges still of interest before
* we perform the is_member test. * we perform the is_member test.
*/ */
remaining = (mask & ~result); remaining = mask & ~result;
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
AclItem *aidata = &aidat[i]; AclItem *aidata = &aidat[i];
...@@ -1042,10 +1042,10 @@ aclmask(const Acl *acl, Oid roleid, Oid ownerId, ...@@ -1042,10 +1042,10 @@ aclmask(const Acl *acl, Oid roleid, Oid ownerId,
if ((aidata->ai_privs & remaining) && if ((aidata->ai_privs & remaining) &&
is_member_of_role(roleid, aidata->ai_grantee)) is_member_of_role(roleid, aidata->ai_grantee))
{ {
result |= (aidata->ai_privs & mask); result |= aidata->ai_privs & mask;
if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0)) if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
return result; return result;
remaining = (mask & ~result); remaining = mask & ~result;
} }
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* workings can be found in the book "Software Solutions in C" by * workings can be found in the book "Software Solutions in C" by
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7. * Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
* *
* $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.64 2004/08/29 05:06:49 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.65 2005/07/21 04:41:43 momjian Exp $
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -197,7 +197,7 @@ cash_in(PG_FUNCTION_ARGS) ...@@ -197,7 +197,7 @@ cash_in(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type money: \"%s\"", str))); errmsg("invalid input syntax for type money: \"%s\"", str)));
result = (value * sgn); result = value * sgn;
#ifdef CASHDEBUG #ifdef CASHDEBUG
printf("cashin- result is %d\n", result); printf("cashin- result is %d\n", result);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.114 2005/07/21 03:56:13 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.115 2005/07/21 04:41:43 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -304,8 +304,7 @@ date2timestamptz(DateADT dateVal) ...@@ -304,8 +304,7 @@ date2timestamptz(DateADT dateVal)
tz = DetermineLocalTimeZone(tm); tz = DetermineLocalTimeZone(tm);
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result = (dateVal * USECS_PER_DAY) result = dateVal * USECS_PER_DAY + tz * USECS_PER_SEC;
+ (tz * USECS_PER_SEC);
#else #else
result = dateVal * (double)SECS_PER_DAY + tz; result = dateVal * (double)SECS_PER_DAY + tz;
#endif #endif
...@@ -725,7 +724,7 @@ timestamp_date(PG_FUNCTION_ARGS) ...@@ -725,7 +724,7 @@ timestamp_date(PG_FUNCTION_ARGS)
if (TIMESTAMP_NOT_FINITE(timestamp)) if (TIMESTAMP_NOT_FINITE(timestamp))
PG_RETURN_NULL(); PG_RETURN_NULL();
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) !=0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -768,7 +767,7 @@ timestamptz_date(PG_FUNCTION_ARGS) ...@@ -768,7 +767,7 @@ timestamptz_date(PG_FUNCTION_ARGS)
if (TIMESTAMP_NOT_FINITE(timestamp)) if (TIMESTAMP_NOT_FINITE(timestamp))
PG_RETURN_NULL(); PG_RETURN_NULL();
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) !=0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -829,7 +828,7 @@ date_text(PG_FUNCTION_ARGS) ...@@ -829,7 +828,7 @@ date_text(PG_FUNCTION_ARGS)
str = DatumGetCString(DirectFunctionCall1(date_out, date)); str = DatumGetCString(DirectFunctionCall1(date_out, date));
len = (strlen(str) + VARHDRSZ); len = strlen(str) + VARHDRSZ;
result = palloc(len); result = palloc(len);
...@@ -1337,7 +1336,7 @@ timestamp_time(PG_FUNCTION_ARGS) ...@@ -1337,7 +1336,7 @@ timestamp_time(PG_FUNCTION_ARGS)
if (TIMESTAMP_NOT_FINITE(timestamp)) if (TIMESTAMP_NOT_FINITE(timestamp))
PG_RETURN_NULL(); PG_RETURN_NULL();
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) !=0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -1374,7 +1373,7 @@ timestamptz_time(PG_FUNCTION_ARGS) ...@@ -1374,7 +1373,7 @@ timestamptz_time(PG_FUNCTION_ARGS)
if (TIMESTAMP_NOT_FINITE(timestamp)) if (TIMESTAMP_NOT_FINITE(timestamp))
PG_RETURN_NULL(); PG_RETURN_NULL();
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) !=0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -1496,14 +1495,14 @@ time_pl_interval(PG_FUNCTION_ARGS) ...@@ -1496,14 +1495,14 @@ time_pl_interval(PG_FUNCTION_ARGS)
TimeADT result; TimeADT result;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result = (time + span->time); result = time + span->time;
result -= (result / USECS_PER_DAY * USECS_PER_DAY); result -= result / USECS_PER_DAY * USECS_PER_DAY;
if (result < INT64CONST(0)) if (result < INT64CONST(0))
result += USECS_PER_DAY; result += USECS_PER_DAY;
#else #else
TimeADT time1; TimeADT time1;
result = (time + span->time); result = time + span->time;
TMODULO(result, time1, (double)SECS_PER_DAY); TMODULO(result, time1, (double)SECS_PER_DAY);
if (result < 0) if (result < 0)
result += SECS_PER_DAY; result += SECS_PER_DAY;
...@@ -1523,14 +1522,14 @@ time_mi_interval(PG_FUNCTION_ARGS) ...@@ -1523,14 +1522,14 @@ time_mi_interval(PG_FUNCTION_ARGS)
TimeADT result; TimeADT result;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result = (time - span->time); result = time - span->time;
result -= (result / USECS_PER_DAY * USECS_PER_DAY); result -= result / USECS_PER_DAY * USECS_PER_DAY;
if (result < INT64CONST(0)) if (result < INT64CONST(0))
result += USECS_PER_DAY; result += USECS_PER_DAY;
#else #else
TimeADT time1; TimeADT time1;
result = (time - span->time); result = time - span->time;
TMODULO(result, time1, (double)SECS_PER_DAY); TMODULO(result, time1, (double)SECS_PER_DAY);
if (result < 0) if (result < 0)
result += SECS_PER_DAY; result += SECS_PER_DAY;
...@@ -1554,7 +1553,7 @@ time_text(PG_FUNCTION_ARGS) ...@@ -1554,7 +1553,7 @@ time_text(PG_FUNCTION_ARGS)
str = DatumGetCString(DirectFunctionCall1(time_out, time)); str = DatumGetCString(DirectFunctionCall1(time_out, time));
len = (strlen(str) + VARHDRSZ); len = strlen(str) + VARHDRSZ;
result = palloc(len); result = palloc(len);
...@@ -1685,7 +1684,7 @@ time_part(PG_FUNCTION_ARGS) ...@@ -1685,7 +1684,7 @@ time_part(PG_FUNCTION_ARGS)
else if (type == RESERV && val == DTK_EPOCH) else if (type == RESERV && val == DTK_EPOCH)
{ {
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result = (time / 1000000.0); result = time / 1000000.0;
#else #else
result = time; result = time;
#endif #endif
...@@ -2036,12 +2035,12 @@ timetz_pl_interval(PG_FUNCTION_ARGS) ...@@ -2036,12 +2035,12 @@ timetz_pl_interval(PG_FUNCTION_ARGS)
result = (TimeTzADT *) palloc(sizeof(TimeTzADT)); result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result->time = (time->time + span->time); result->time = time->time + span->time;
result->time -= (result->time / USECS_PER_DAY * USECS_PER_DAY); result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
if (result->time < INT64CONST(0)) if (result->time < INT64CONST(0))
result->time += USECS_PER_DAY; result->time += USECS_PER_DAY;
#else #else
result->time = (time->time + span->time); result->time = time->time + span->time;
TMODULO(result->time, time1.time, (double)SECS_PER_DAY); TMODULO(result->time, time1.time, (double)SECS_PER_DAY);
if (result->time < 0) if (result->time < 0)
result->time += SECS_PER_DAY; result->time += SECS_PER_DAY;
...@@ -2069,12 +2068,12 @@ timetz_mi_interval(PG_FUNCTION_ARGS) ...@@ -2069,12 +2068,12 @@ timetz_mi_interval(PG_FUNCTION_ARGS)
result = (TimeTzADT *) palloc(sizeof(TimeTzADT)); result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result->time = (time->time - span->time); result->time = time->time - span->time;
result->time -= (result->time / USECS_PER_DAY * USECS_PER_DAY); result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
if (result->time < INT64CONST(0)) if (result->time < INT64CONST(0))
result->time += USECS_PER_DAY; result->time += USECS_PER_DAY;
#else #else
result->time = (time->time - span->time); result->time = time->time - span->time;
TMODULO(result->time, time1.time, (double)SECS_PER_DAY); TMODULO(result->time, time1.time, (double)SECS_PER_DAY);
if (result->time < 0) if (result->time < 0)
result->time += SECS_PER_DAY; result->time += SECS_PER_DAY;
...@@ -2265,7 +2264,7 @@ timestamptz_timetz(PG_FUNCTION_ARGS) ...@@ -2265,7 +2264,7 @@ timestamptz_timetz(PG_FUNCTION_ARGS)
if (TIMESTAMP_NOT_FINITE(timestamp)) if (TIMESTAMP_NOT_FINITE(timestamp))
PG_RETURN_NULL(); PG_RETURN_NULL();
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) !=0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -2315,7 +2314,7 @@ timetz_text(PG_FUNCTION_ARGS) ...@@ -2315,7 +2314,7 @@ timetz_text(PG_FUNCTION_ARGS)
str = DatumGetCString(DirectFunctionCall1(timetz_out, timetz)); str = DatumGetCString(DirectFunctionCall1(timetz_out, timetz));
len = (strlen(str) + VARHDRSZ); len = strlen(str) + VARHDRSZ;
result = palloc(len); result = palloc(len);
...@@ -2497,7 +2496,8 @@ timetz_zone(PG_FUNCTION_ARGS) ...@@ -2497,7 +2496,8 @@ timetz_zone(PG_FUNCTION_ARGS)
pg_time_t now; pg_time_t now;
/* Find the specified timezone */ /* Find the specified timezone */
len = (VARSIZE(zone)-VARHDRSZ>TZ_STRLEN_MAX)?TZ_STRLEN_MAX:(VARSIZE(zone)-VARHDRSZ); len = (VARSIZE(zone)-VARHDRSZ>TZ_STRLEN_MAX) ?
TZ_STRLEN_MAX : VARSIZE(zone) - VARHDRSZ;
memcpy(tzname,VARDATA(zone),len); memcpy(tzname,VARDATA(zone),len);
tzname[len]=0; tzname[len]=0;
tzp = pg_tzset(tzname); tzp = pg_tzset(tzname);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.153 2005/07/21 03:56:14 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.154 2005/07/21 04:41:43 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -3275,8 +3275,8 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm, ...@@ -3275,8 +3275,8 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
int sec; int sec;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
sec = (*fsec / USECS_PER_SEC); sec = *fsec / USECS_PER_SEC;
*fsec -= (sec * USECS_PER_SEC); *fsec -= sec * USECS_PER_SEC;
#else #else
TMODULO(*fsec, sec, 1.0); TMODULO(*fsec, sec, 1.0);
#endif #endif
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.137 2005/07/21 03:56:18 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.138 2005/07/21 04:41:43 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -49,8 +49,8 @@ ...@@ -49,8 +49,8 @@
#define IsSpace(C) ((C) == ' ') #define IsSpace(C) ((C) == ' ')
#define T_INTERVAL_INVAL 0 /* data represents no valid interval */ #define T_INTERVAL_INVAL 0 /* data represents no valid tinterval */
#define T_INTERVAL_VALID 1 /* data represents a valid interval */ #define T_INTERVAL_VALID 1 /* data represents a valid tinterval */
/* /*
* ['Mon May 10 23:59:12 1943 PST' 'Sun Jan 14 03:14:21 1973 PST'] * ['Mon May 10 23:59:12 1943 PST' 'Sun Jan 14 03:14:21 1973 PST']
* 0 1 2 3 4 5 6 * 0 1 2 3 4 5 6
...@@ -712,64 +712,64 @@ reltime2tm(RelativeTime time, struct pg_tm * tm) ...@@ -712,64 +712,64 @@ reltime2tm(RelativeTime time, struct pg_tm * tm)
/* /*
* tintervalin - converts an interval string to internal format * tintervalin - converts an tinterval string to internal format
*/ */
Datum Datum
tintervalin(PG_FUNCTION_ARGS) tintervalin(PG_FUNCTION_ARGS)
{ {
char *intervalstr = PG_GETARG_CSTRING(0); char *tintervalstr = PG_GETARG_CSTRING(0);
TimeInterval interval; TimeInterval tinterval;
AbsoluteTime i_start, AbsoluteTime i_start,
i_end, i_end,
t1, t1,
t2; t2;
interval = (TimeInterval) palloc(sizeof(TimeIntervalData)); tinterval = (TimeInterval) palloc(sizeof(TimeIntervalData));
if (istinterval(intervalstr, &t1, &t2) == 0) if (istinterval(tintervalstr, &t1, &t2) == 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT), (errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for type tinterval: \"%s\"", errmsg("invalid input syntax for type tinterval: \"%s\"",
intervalstr))); tintervalstr)));
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
interval ->status = T_INTERVAL_INVAL; /* undefined */ tinterval ->status = T_INTERVAL_INVAL; /* undefined */
else else
interval ->status = T_INTERVAL_VALID; tinterval ->status = T_INTERVAL_VALID;
i_start = ABSTIMEMIN(t1, t2); i_start = ABSTIMEMIN(t1, t2);
i_end = ABSTIMEMAX(t1, t2); i_end = ABSTIMEMAX(t1, t2);
interval ->data[0] = i_start; tinterval ->data[0] = i_start;
interval ->data[1] = i_end; tinterval ->data[1] = i_end;
PG_RETURN_TIMEINTERVAL(interval); PG_RETURN_TIMEINTERVAL(tinterval);
} }
/* /*
* tintervalout - converts an internal interval format to a string * tintervalout - converts an internal tinterval format to a string
*/ */
Datum Datum
tintervalout(PG_FUNCTION_ARGS) tintervalout(PG_FUNCTION_ARGS)
{ {
TimeInterval interval = PG_GETARG_TIMEINTERVAL(0); TimeInterval tinterval = PG_GETARG_TIMEINTERVAL(0);
char *i_str, char *i_str,
*p; *p;
i_str = (char *) palloc(T_INTERVAL_LEN); /* ["..." "..."] */ i_str = (char *) palloc(T_INTERVAL_LEN); /* ["..." "..."] */
strcpy(i_str, "[\""); strcpy(i_str, "[\"");
if (interval->status == T_INTERVAL_INVAL) if (tinterval->status == T_INTERVAL_INVAL)
strcat(i_str, INVALID_INTERVAL_STR); strcat(i_str, INVALID_INTERVAL_STR);
else else
{ {
p = DatumGetCString(DirectFunctionCall1(abstimeout, p = DatumGetCString(DirectFunctionCall1(abstimeout,
AbsoluteTimeGetDatum(interval->data[0]))); AbsoluteTimeGetDatum(tinterval->data[0])));
strcat(i_str, p); strcat(i_str, p);
pfree(p); pfree(p);
strcat(i_str, "\" \""); strcat(i_str, "\" \"");
p = DatumGetCString(DirectFunctionCall1(abstimeout, p = DatumGetCString(DirectFunctionCall1(abstimeout,
AbsoluteTimeGetDatum(interval->data[1]))); AbsoluteTimeGetDatum(tinterval->data[1])));
strcat(i_str, p); strcat(i_str, p);
pfree(p); pfree(p);
} }
...@@ -784,22 +784,22 @@ Datum ...@@ -784,22 +784,22 @@ Datum
tintervalrecv(PG_FUNCTION_ARGS) tintervalrecv(PG_FUNCTION_ARGS)
{ {
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
TimeInterval interval; TimeInterval tinterval;
interval = (TimeInterval) palloc(sizeof(TimeIntervalData)); tinterval = (TimeInterval) palloc(sizeof(TimeIntervalData));
interval ->status = pq_getmsgint(buf, sizeof(interval->status)); tinterval ->status = pq_getmsgint(buf, sizeof(tinterval->status));
if (!(interval->status == T_INTERVAL_INVAL || if (!(tinterval->status == T_INTERVAL_INVAL ||
interval->status == T_INTERVAL_VALID)) tinterval->status == T_INTERVAL_VALID))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION), (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid status in external \"tinterval\" value"))); errmsg("invalid status in external \"tinterval\" value")));
interval ->data[0] = pq_getmsgint(buf, sizeof(interval->data[0])); tinterval ->data[0] = pq_getmsgint(buf, sizeof(tinterval->data[0]));
interval ->data[1] = pq_getmsgint(buf, sizeof(interval->data[1])); tinterval ->data[1] = pq_getmsgint(buf, sizeof(tinterval->data[1]));
PG_RETURN_TIMEINTERVAL(interval); PG_RETURN_TIMEINTERVAL(tinterval);
} }
/* /*
...@@ -808,13 +808,13 @@ tintervalrecv(PG_FUNCTION_ARGS) ...@@ -808,13 +808,13 @@ tintervalrecv(PG_FUNCTION_ARGS)
Datum Datum
tintervalsend(PG_FUNCTION_ARGS) tintervalsend(PG_FUNCTION_ARGS)
{ {
TimeInterval interval = PG_GETARG_TIMEINTERVAL(0); TimeInterval tinterval = PG_GETARG_TIMEINTERVAL(0);
StringInfoData buf; StringInfoData buf;
pq_begintypsend(&buf); pq_begintypsend(&buf);
pq_sendint(&buf, interval->status, sizeof(interval->status)); pq_sendint(&buf, tinterval->status, sizeof(tinterval->status));
pq_sendint(&buf, interval->data[0], sizeof(interval->data[0])); pq_sendint(&buf, tinterval->data[0], sizeof(tinterval->data[0]));
pq_sendint(&buf, interval->data[1], sizeof(interval->data[1])); pq_sendint(&buf, tinterval->data[1], sizeof(tinterval->data[1]));
PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
} }
...@@ -884,10 +884,10 @@ reltime_interval(PG_FUNCTION_ARGS) ...@@ -884,10 +884,10 @@ reltime_interval(PG_FUNCTION_ARGS)
default: default:
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
year = (reltime / (36525 * 864)); year = reltime / (36525 * 864);
reltime -= (year * (36525 * 864)); reltime -= year * (36525 * 864);
month = (reltime / (DAYS_PER_MONTH * SECS_PER_DAY)); month = reltime / (DAYS_PER_MONTH * SECS_PER_DAY);
reltime -= (month * (DAYS_PER_MONTH * SECS_PER_DAY)); reltime -= month * (DAYS_PER_MONTH * SECS_PER_DAY);
day = reltime / SECS_PER_DAY; day = reltime / SECS_PER_DAY;
reltime -= day * SECS_PER_DAY; reltime -= day * SECS_PER_DAY;
...@@ -918,21 +918,21 @@ mktinterval(PG_FUNCTION_ARGS) ...@@ -918,21 +918,21 @@ mktinterval(PG_FUNCTION_ARGS)
AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1);
AbsoluteTime tstart = ABSTIMEMIN(t1, t2); AbsoluteTime tstart = ABSTIMEMIN(t1, t2);
AbsoluteTime tend = ABSTIMEMAX(t1, t2); AbsoluteTime tend = ABSTIMEMAX(t1, t2);
TimeInterval interval; TimeInterval tinterval;
interval = (TimeInterval) palloc(sizeof(TimeIntervalData)); tinterval = (TimeInterval) palloc(sizeof(TimeIntervalData));
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
interval ->status = T_INTERVAL_INVAL; tinterval->status = T_INTERVAL_INVAL;
else else
{ {
interval ->status = T_INTERVAL_VALID; tinterval->status = T_INTERVAL_VALID;
interval ->data[0] = tstart; tinterval->data[0] = tstart;
interval ->data[1] = tend; tinterval->data[1] = tend;
} }
PG_RETURN_TIMEINTERVAL(interval); PG_RETURN_TIMEINTERVAL(tinterval);
} }
/* /*
...@@ -981,38 +981,38 @@ timemi(PG_FUNCTION_ARGS) ...@@ -981,38 +981,38 @@ timemi(PG_FUNCTION_ARGS)
/* /*
* intinterval - returns true iff absolute date is in the interval * intinterval - returns true iff absolute date is in the tinterval
*/ */
Datum Datum
intinterval(PG_FUNCTION_ARGS) intinterval(PG_FUNCTION_ARGS)
{ {
AbsoluteTime t = PG_GETARG_ABSOLUTETIME(0); AbsoluteTime t = PG_GETARG_ABSOLUTETIME(0);
TimeInterval interval = PG_GETARG_TIMEINTERVAL(1); TimeInterval tinterval = PG_GETARG_TIMEINTERVAL(1);
if (interval->status == T_INTERVAL_VALID && t != INVALID_ABSTIME) if (tinterval->status == T_INTERVAL_VALID && t != INVALID_ABSTIME)
{ {
if (DatumGetBool(DirectFunctionCall2(abstimege, if (DatumGetBool(DirectFunctionCall2(abstimege,
AbsoluteTimeGetDatum(t), AbsoluteTimeGetDatum(t),
AbsoluteTimeGetDatum(interval->data[0]))) && AbsoluteTimeGetDatum(tinterval->data[0]))) &&
DatumGetBool(DirectFunctionCall2(abstimele, DatumGetBool(DirectFunctionCall2(abstimele,
AbsoluteTimeGetDatum(t), AbsoluteTimeGetDatum(t),
AbsoluteTimeGetDatum(interval->data[1])))) AbsoluteTimeGetDatum(tinterval->data[1]))))
PG_RETURN_BOOL(true); PG_RETURN_BOOL(true);
} }
PG_RETURN_BOOL(false); PG_RETURN_BOOL(false);
} }
/* /*
* tintervalrel - returns relative time corresponding to interval * tintervalrel - returns relative time corresponding to tinterval
*/ */
Datum Datum
tintervalrel(PG_FUNCTION_ARGS) tintervalrel(PG_FUNCTION_ARGS)
{ {
TimeInterval interval = PG_GETARG_TIMEINTERVAL(0); TimeInterval tinterval = PG_GETARG_TIMEINTERVAL(0);
AbsoluteTime t1 = interval->data[0]; AbsoluteTime t1 = tinterval->data[0];
AbsoluteTime t2 = interval->data[1]; AbsoluteTime t2 = tinterval->data[1];
if (interval->status != T_INTERVAL_VALID) if (tinterval->status != T_INTERVAL_VALID)
PG_RETURN_RELATIVETIME(INVALID_RELTIME); PG_RETURN_RELATIVETIME(INVALID_RELTIME);
if (AbsoluteTimeIsReal(t1) && if (AbsoluteTimeIsReal(t1) &&
...@@ -1134,7 +1134,7 @@ btreltimecmp(PG_FUNCTION_ARGS) ...@@ -1134,7 +1134,7 @@ btreltimecmp(PG_FUNCTION_ARGS)
/* /*
* tintervalsame - returns true iff interval i1 is same as interval i2 * tintervalsame - returns true iff tinterval i1 is same as tinterval i2
* Check begin and end time. * Check begin and end time.
*/ */
Datum Datum
...@@ -1159,7 +1159,7 @@ tintervalsame(PG_FUNCTION_ARGS) ...@@ -1159,7 +1159,7 @@ tintervalsame(PG_FUNCTION_ARGS)
/* /*
* tinterval comparison routines * tinterval comparison routines
* *
* Note: comparison is based on the lengths of the intervals, not on * Note: comparison is based on the lengths of the tintervals, not on
* endpoint value. This is pretty bogus, but since it's only a legacy * endpoint value. This is pretty bogus, but since it's only a legacy
* datatype I'm not going to propose changing it. * datatype I'm not going to propose changing it.
*/ */
...@@ -1270,17 +1270,17 @@ bttintervalcmp(PG_FUNCTION_ARGS) ...@@ -1270,17 +1270,17 @@ bttintervalcmp(PG_FUNCTION_ARGS)
/* /*
* tintervalleneq - returns true iff length of interval i is equal to * tintervalleneq - returns true iff length of tinterval i is equal to
* reltime t * reltime t
* tintervallenne - returns true iff length of interval i is not equal * tintervallenne - returns true iff length of tinterval i is not equal
* to reltime t * to reltime t
* tintervallenlt - returns true iff length of interval i is less than * tintervallenlt - returns true iff length of tinterval i is less than
* reltime t * reltime t
* tintervallengt - returns true iff length of interval i is greater * tintervallengt - returns true iff length of tinterval i is greater
* than reltime t * than reltime t
* tintervallenle - returns true iff length of interval i is less or * tintervallenle - returns true iff length of tinterval i is less or
* equal than reltime t * equal than reltime t
* tintervallenge - returns true iff length of interval i is greater or * tintervallenge - returns true iff length of tinterval i is greater or
* equal than reltime t * equal than reltime t
*/ */
Datum Datum
...@@ -1368,7 +1368,7 @@ tintervallenge(PG_FUNCTION_ARGS) ...@@ -1368,7 +1368,7 @@ tintervallenge(PG_FUNCTION_ARGS)
} }
/* /*
* tintervalct - returns true iff interval i1 contains interval i2 * tintervalct - returns true iff tinterval i1 contains tinterval i2
*/ */
Datum Datum
tintervalct(PG_FUNCTION_ARGS) tintervalct(PG_FUNCTION_ARGS)
...@@ -1389,7 +1389,7 @@ tintervalct(PG_FUNCTION_ARGS) ...@@ -1389,7 +1389,7 @@ tintervalct(PG_FUNCTION_ARGS)
} }
/* /*
* tintervalov - returns true iff interval i1 (partially) overlaps i2 * tintervalov - returns true iff tinterval i1 (partially) overlaps i2
*/ */
Datum Datum
tintervalov(PG_FUNCTION_ARGS) tintervalov(PG_FUNCTION_ARGS)
...@@ -1410,7 +1410,7 @@ tintervalov(PG_FUNCTION_ARGS) ...@@ -1410,7 +1410,7 @@ tintervalov(PG_FUNCTION_ARGS)
} }
/* /*
* tintervalstart - returns the start of interval i * tintervalstart - returns the start of tinterval i
*/ */
Datum Datum
tintervalstart(PG_FUNCTION_ARGS) tintervalstart(PG_FUNCTION_ARGS)
...@@ -1423,7 +1423,7 @@ tintervalstart(PG_FUNCTION_ARGS) ...@@ -1423,7 +1423,7 @@ tintervalstart(PG_FUNCTION_ARGS)
} }
/* /*
* tintervalend - returns the end of interval i * tintervalend - returns the end of tinterval i
*/ */
Datum Datum
tintervalend(PG_FUNCTION_ARGS) tintervalend(PG_FUNCTION_ARGS)
...@@ -1441,12 +1441,12 @@ tintervalend(PG_FUNCTION_ARGS) ...@@ -1441,12 +1441,12 @@ tintervalend(PG_FUNCTION_ARGS)
*****************************************************************************/ *****************************************************************************/
/* /*
* istinterval - returns 1, iff i_string is a valid interval descr. * istinterval - returns 1, iff i_string is a valid tinterval descr.
* 0, iff i_string is NOT a valid interval desc. * 0, iff i_string is NOT a valid tinterval desc.
* 2, iff any time is INVALID_ABSTIME * 2, iff any time is INVALID_ABSTIME
* *
* output parameter: * output parameter:
* i_start, i_end: interval margins * i_start, i_end: tinterval margins
* *
* Time interval: * Time interval:
* `[' {` '} `'' <AbsTime> `'' {` '} `'' <AbsTime> `'' {` '} `]' * `[' {` '} `'' <AbsTime> `'' {` '} `'' <AbsTime> `'' {` '} `]'
...@@ -1551,7 +1551,7 @@ istinterval(char *i_string, ...@@ -1551,7 +1551,7 @@ istinterval(char *i_string,
c = *p; c = *p;
if (c != '\0') if (c != '\0')
return 0; /* syntax error */ return 0; /* syntax error */
/* it seems to be a valid interval */ /* it seems to be a valid tinterval */
return 1; return 1;
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.186 2005/07/21 03:56:18 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.187 2005/07/21 04:41:43 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2799,14 +2799,14 @@ convert_timevalue_to_scalar(Datum value, Oid typid) ...@@ -2799,14 +2799,14 @@ convert_timevalue_to_scalar(Datum value, Oid typid)
#endif #endif
case TINTERVALOID: case TINTERVALOID:
{ {
TimeInterval interval = DatumGetTimeInterval(value); TimeInterval tinterval = DatumGetTimeInterval(value);
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
if (interval->status != 0) if (tinterval->status != 0)
return ((interval->data[1] - interval->data[0]) * 1000000.0); return ((tinterval->data[1] - tinterval->data[0]) * 1000000.0);
#else #else
if (interval->status != 0) if (tinterval->status != 0)
return interval->data[1] - interval->data[0]; return tinterval->data[1] - tinterval->data[0];
#endif #endif
return 0; /* for lack of a better idea */ return 0; /* for lack of a better idea */
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.135 2005/07/21 03:56:20 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.136 2005/07/21 04:41:43 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -433,7 +433,7 @@ timestamptz_recv(PG_FUNCTION_ARGS) ...@@ -433,7 +433,7 @@ timestamptz_recv(PG_FUNCTION_ARGS)
/* rangecheck: see if timestamptz_out would like it */ /* rangecheck: see if timestamptz_out would like it */
if (TIMESTAMP_NOT_FINITE(timestamp)) if (TIMESTAMP_NOT_FINITE(timestamp))
/* ok */ ; /* ok */ ;
else if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) !=0) else if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -1186,12 +1186,12 @@ interval2tm(Interval span, struct pg_tm *tm, fsec_t *fsec) ...@@ -1186,12 +1186,12 @@ interval2tm(Interval span, struct pg_tm *tm, fsec_t *fsec)
time = span.time; time = span.time;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
tm->tm_hour = (time / USECS_PER_HOUR); tm->tm_hour = time / USECS_PER_HOUR;
time -= (tm->tm_hour * USECS_PER_HOUR); time -= tm->tm_hour * USECS_PER_HOUR;
tm->tm_min = (time / USECS_PER_MINUTE); tm->tm_min = time / USECS_PER_MINUTE;
time -= (tm->tm_min * USECS_PER_MINUTE); time -= tm->tm_min * USECS_PER_MINUTE;
tm->tm_sec = (time / USECS_PER_SEC); tm->tm_sec = time / USECS_PER_SEC;
*fsec = (time - (tm->tm_sec * USECS_PER_SEC)); *fsec = time - (tm->tm_sec * USECS_PER_SEC);
#else #else
TMODULO(time, tm->tm_hour, (double)SECS_PER_HOUR); TMODULO(time, tm->tm_hour, (double)SECS_PER_HOUR);
TMODULO(time, tm->tm_min, (double)SECS_PER_MINUTE); TMODULO(time, tm->tm_min, (double)SECS_PER_MINUTE);
...@@ -1883,7 +1883,7 @@ timestamp_mi(PG_FUNCTION_ARGS) ...@@ -1883,7 +1883,7 @@ timestamp_mi(PG_FUNCTION_ARGS)
} }
else else
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result->time = (dt1 - dt2); result->time = dt1 - dt2;
#else #else
result->time = JROUND(dt1 - dt2); result->time = JROUND(dt1 - dt2);
#endif #endif
...@@ -1978,7 +1978,7 @@ timestamp_pl_interval(PG_FUNCTION_ARGS) ...@@ -1978,7 +1978,7 @@ timestamp_pl_interval(PG_FUNCTION_ARGS)
*tm = &tt; *tm = &tt;
fsec_t fsec; fsec_t fsec;
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) !=0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -1999,7 +1999,7 @@ timestamp_pl_interval(PG_FUNCTION_ARGS) ...@@ -1999,7 +1999,7 @@ timestamp_pl_interval(PG_FUNCTION_ARGS)
if (tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]) if (tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1])
tm->tm_mday = (day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]); tm->tm_mday = (day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]);
if (tm2timestamp(tm, fsec, NULL, &timestamp) !=0) if (tm2timestamp(tm, fsec, NULL, &timestamp) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -2012,7 +2012,7 @@ timestamp_pl_interval(PG_FUNCTION_ARGS) ...@@ -2012,7 +2012,7 @@ timestamp_pl_interval(PG_FUNCTION_ARGS)
fsec_t fsec; fsec_t fsec;
int julian; int julian;
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) !=0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -2021,7 +2021,7 @@ timestamp_pl_interval(PG_FUNCTION_ARGS) ...@@ -2021,7 +2021,7 @@ timestamp_pl_interval(PG_FUNCTION_ARGS)
julian = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) + span->day; julian = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) + span->day;
j2date(julian, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); j2date(julian, &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
if (tm2timestamp(tm, fsec, NULL, &timestamp) !=0) if (tm2timestamp(tm, fsec, NULL, &timestamp) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -2079,7 +2079,7 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS) ...@@ -2079,7 +2079,7 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS)
*tm = &tt; *tm = &tt;
fsec_t fsec; fsec_t fsec;
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) !=0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -2102,7 +2102,7 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS) ...@@ -2102,7 +2102,7 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS)
tz = DetermineLocalTimeZone(tm); tz = DetermineLocalTimeZone(tm);
if (tm2timestamp(tm, fsec, &tz, &timestamp) !=0) if (tm2timestamp(tm, fsec, &tz, &timestamp) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -2115,7 +2115,7 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS) ...@@ -2115,7 +2115,7 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS)
fsec_t fsec; fsec_t fsec;
int julian; int julian;
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) !=0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -2126,7 +2126,7 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS) ...@@ -2126,7 +2126,7 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS)
tz = DetermineLocalTimeZone(tm); tz = DetermineLocalTimeZone(tm);
if (tm2timestamp(tm, fsec, &tz, &timestamp) !=0) if (tm2timestamp(tm, fsec, &tz, &timestamp) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -2164,9 +2164,9 @@ interval_um(PG_FUNCTION_ARGS) ...@@ -2164,9 +2164,9 @@ interval_um(PG_FUNCTION_ARGS)
result = (Interval *) palloc(sizeof(Interval)); result = (Interval *) palloc(sizeof(Interval));
result->time = -(interval->time); result->time = -interval->time;
result->day = -(interval->day); result->day = -interval->day;
result->month = -(interval->month); result->month = -interval->month;
PG_RETURN_INTERVAL_P(result); PG_RETURN_INTERVAL_P(result);
} }
...@@ -2210,10 +2210,10 @@ interval_pl(PG_FUNCTION_ARGS) ...@@ -2210,10 +2210,10 @@ interval_pl(PG_FUNCTION_ARGS)
result = (Interval *) palloc(sizeof(Interval)); result = (Interval *) palloc(sizeof(Interval));
result->month = (span1->month + span2->month); result->month = span1->month + span2->month;
result->day = (span1->day + span2->day); result->day = span1->day + span2->day;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result->time = (span1->time + span2->time); result->time = span1->time + span2->time;
#else #else
result->time = JROUND(span1->time + span2->time); result->time = JROUND(span1->time + span2->time);
#endif #endif
...@@ -2230,10 +2230,10 @@ interval_mi(PG_FUNCTION_ARGS) ...@@ -2230,10 +2230,10 @@ interval_mi(PG_FUNCTION_ARGS)
result = (Interval *) palloc(sizeof(Interval)); result = (Interval *) palloc(sizeof(Interval));
result->month = (span1->month - span2->month); result->month = span1->month - span2->month;
result->day = (span1->day - span2->day); result->day = span1->day - span2->day;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result->time = (span1->time - span2->time); result->time = span1->time - span2->time;
#else #else
result->time = JROUND(span1->time - span2->time); result->time = JROUND(span1->time - span2->time);
#endif #endif
...@@ -2258,12 +2258,12 @@ interval_mul(PG_FUNCTION_ARGS) ...@@ -2258,12 +2258,12 @@ interval_mul(PG_FUNCTION_ARGS)
result = (Interval *) palloc(sizeof(Interval)); result = (Interval *) palloc(sizeof(Interval));
months = (span1->month * factor); months = span1->month * factor;
days = (span1->day * factor); days = span1->day * factor;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result->month = months; result->month = months;
result->day = days; result->day = days;
result->time = (span1->time * factor); result->time = span1->time * factor;
result->time += (months - result->month) * INT64CONST(DAYS_PER_MONTH) * USECS_PER_DAY; result->time += (months - result->month) * INT64CONST(DAYS_PER_MONTH) * USECS_PER_DAY;
result->time += (days - result->day) * INT64CONST(HOURS_PER_DAY) * USECS_PER_HOUR; result->time += (days - result->day) * INT64CONST(HOURS_PER_DAY) * USECS_PER_HOUR;
#else #else
...@@ -2862,7 +2862,7 @@ timestamp_trunc(PG_FUNCTION_ARGS) ...@@ -2862,7 +2862,7 @@ timestamp_trunc(PG_FUNCTION_ARGS)
if (type == UNITS) if (type == UNITS)
{ {
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) !=0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -2996,7 +2996,7 @@ timestamptz_trunc(PG_FUNCTION_ARGS) ...@@ -2996,7 +2996,7 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
if (type == UNITS) if (type == UNITS)
{ {
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) !=0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -3390,7 +3390,7 @@ timestamp_part(PG_FUNCTION_ARGS) ...@@ -3390,7 +3390,7 @@ timestamp_part(PG_FUNCTION_ARGS)
if (type == UNITS) if (type == UNITS)
{ {
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) !=0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -3461,7 +3461,7 @@ timestamp_part(PG_FUNCTION_ARGS) ...@@ -3461,7 +3461,7 @@ timestamp_part(PG_FUNCTION_ARGS)
* and -1 is 11 BC thru 2 BC... * and -1 is 11 BC thru 2 BC...
*/ */
if (tm->tm_year >= 0) if (tm->tm_year >= 0)
result = (tm->tm_year / 10); result = tm->tm_year / 10;
else else
result = -((8 - (tm->tm_year - 1)) / 10); result = -((8 - (tm->tm_year - 1)) / 10);
break; break;
...@@ -3484,7 +3484,7 @@ timestamp_part(PG_FUNCTION_ARGS) ...@@ -3484,7 +3484,7 @@ timestamp_part(PG_FUNCTION_ARGS)
case DTK_MILLENNIUM: case DTK_MILLENNIUM:
/* see comments above. */ /* see comments above. */
if (tm->tm_year > 0) if (tm->tm_year > 0)
result = ((tm->tm_year + 999) / 1000); result = (tm->tm_year + 999) / 1000;
else else
result = -((999 - (tm->tm_year - 1)) / 1000); result = -((999 - (tm->tm_year - 1)) / 1000);
break; break;
...@@ -3524,7 +3524,7 @@ timestamp_part(PG_FUNCTION_ARGS) ...@@ -3524,7 +3524,7 @@ timestamp_part(PG_FUNCTION_ARGS)
* convert to timestamptz to produce consistent * convert to timestamptz to produce consistent
* results * results
*/ */
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) !=0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -3544,7 +3544,7 @@ timestamp_part(PG_FUNCTION_ARGS) ...@@ -3544,7 +3544,7 @@ timestamp_part(PG_FUNCTION_ARGS)
break; break;
} }
case DTK_DOW: case DTK_DOW:
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) !=0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -3552,7 +3552,7 @@ timestamp_part(PG_FUNCTION_ARGS) ...@@ -3552,7 +3552,7 @@ timestamp_part(PG_FUNCTION_ARGS)
break; break;
case DTK_DOY: case DTK_DOY:
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) !=0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -3615,7 +3615,7 @@ timestamptz_part(PG_FUNCTION_ARGS) ...@@ -3615,7 +3615,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
if (type == UNITS) if (type == UNITS)
{ {
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) !=0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -3696,7 +3696,7 @@ timestamptz_part(PG_FUNCTION_ARGS) ...@@ -3696,7 +3696,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
case DTK_DECADE: case DTK_DECADE:
/* see comments in timestamp_part */ /* see comments in timestamp_part */
if (tm->tm_year > 0) if (tm->tm_year > 0)
result = (tm->tm_year / 10); result = tm->tm_year / 10;
else else
result = -((8 - (tm->tm_year - 1)) / 10); result = -((8 - (tm->tm_year - 1)) / 10);
break; break;
...@@ -3750,7 +3750,7 @@ timestamptz_part(PG_FUNCTION_ARGS) ...@@ -3750,7 +3750,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
break; break;
case DTK_DOW: case DTK_DOW:
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) !=0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -3758,7 +3758,7 @@ timestamptz_part(PG_FUNCTION_ARGS) ...@@ -3758,7 +3758,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
break; break;
case DTK_DOY: case DTK_DOY:
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) !=0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -3868,17 +3868,17 @@ interval_part(PG_FUNCTION_ARGS) ...@@ -3868,17 +3868,17 @@ interval_part(PG_FUNCTION_ARGS)
case DTK_DECADE: case DTK_DECADE:
/* caution: C division may have negative remainder */ /* caution: C division may have negative remainder */
result = (tm->tm_year / 10); result = tm->tm_year / 10;
break; break;
case DTK_CENTURY: case DTK_CENTURY:
/* caution: C division may have negative remainder */ /* caution: C division may have negative remainder */
result = (tm->tm_year / 100); result = tm->tm_year / 100;
break; break;
case DTK_MILLENNIUM: case DTK_MILLENNIUM:
/* caution: C division may have negative remainder */ /* caution: C division may have negative remainder */
result = (tm->tm_year / 1000); result = tm->tm_year / 1000;
break; break;
default: default:
...@@ -4025,7 +4025,7 @@ timestamp2timestamptz(Timestamp timestamp) ...@@ -4025,7 +4025,7 @@ timestamp2timestamptz(Timestamp timestamp)
else else
{ {
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) !=0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
...@@ -4060,7 +4060,7 @@ timestamptz_timestamp(PG_FUNCTION_ARGS) ...@@ -4060,7 +4060,7 @@ timestamptz_timestamp(PG_FUNCTION_ARGS)
else else
{ {
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) !=0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range"))); errmsg("timestamp out of range")));
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.128 2005/07/10 21:13:59 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.129 2005/07/21 04:41:43 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -455,11 +455,11 @@ textcat(PG_FUNCTION_ARGS) ...@@ -455,11 +455,11 @@ textcat(PG_FUNCTION_ARGS)
text *result; text *result;
char *ptr; char *ptr;
len1 = (VARSIZE(t1) - VARHDRSZ); len1 = VARSIZE(t1) - VARHDRSZ;
if (len1 < 0) if (len1 < 0)
len1 = 0; len1 = 0;
len2 = (VARSIZE(t2) - VARHDRSZ); len2 = VARSIZE(t2) - VARHDRSZ;
if (len2 < 0) if (len2 < 0)
len2 = 0; len2 = 0;
...@@ -756,8 +756,8 @@ text_position(text *t1, text *t2, int matchnum) ...@@ -756,8 +756,8 @@ text_position(text *t1, text *t2, int matchnum)
if (VARSIZE(t2) <= VARHDRSZ) if (VARSIZE(t2) <= VARHDRSZ)
return 1; /* result for empty pattern */ return 1; /* result for empty pattern */
len1 = (VARSIZE(t1) - VARHDRSZ); len1 = VARSIZE(t1) - VARHDRSZ;
len2 = (VARSIZE(t2) - VARHDRSZ); len2 = VARSIZE(t2) - VARHDRSZ;
if (pg_database_encoding_max_length() == 1) if (pg_database_encoding_max_length() == 1)
{ {
...@@ -1224,11 +1224,11 @@ byteacat(PG_FUNCTION_ARGS) ...@@ -1224,11 +1224,11 @@ byteacat(PG_FUNCTION_ARGS)
bytea *result; bytea *result;
char *ptr; char *ptr;
len1 = (VARSIZE(t1) - VARHDRSZ); len1 = VARSIZE(t1) - VARHDRSZ;
if (len1 < 0) if (len1 < 0)
len1 = 0; len1 = 0;
len2 = (VARSIZE(t2) - VARHDRSZ); len2 = VARSIZE(t2) - VARHDRSZ;
if (len2 < 0) if (len2 < 0)
len2 = 0; len2 = 0;
...@@ -1349,8 +1349,8 @@ byteapos(PG_FUNCTION_ARGS) ...@@ -1349,8 +1349,8 @@ byteapos(PG_FUNCTION_ARGS)
if (VARSIZE(t2) <= VARHDRSZ) if (VARSIZE(t2) <= VARHDRSZ)
PG_RETURN_INT32(1); /* result for empty pattern */ PG_RETURN_INT32(1); /* result for empty pattern */
len1 = (VARSIZE(t1) - VARHDRSZ); len1 = VARSIZE(t1) - VARHDRSZ;
len2 = (VARSIZE(t2) - VARHDRSZ); len2 = VARSIZE(t2) - VARHDRSZ;
p1 = VARDATA(t1); p1 = VARDATA(t1);
p2 = VARDATA(t2); p2 = VARDATA(t2);
......
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