Commit 9310075a authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Accept an INTERVAL argument for SET TIME ZONE per SQL99.

 Modified the parser and the SET handlers to use full Node structures
 rather than simply a character string argument.
Implement INTERVAL() YEAR TO MONTH (etc) syntax per SQL99.
 Does not yet accept the goofy string format that goes along with, but
 this should be fairly straight forward to fix now as a bug or later
 as a feature.
Implement precision for the INTERVAL() type.
 Use the typmod mechanism for both of INTERVAL features.
Fix the INTERVAL syntax in the parser:
 opt_interval was in the wrong place.
INTERVAL is now a reserved word, otherwise we get reduce/reduce errors.
Implement an explicit date_part() function for TIMETZ.
 Should fix coersion problem with INTERVAL reported by Peter E.
Fix up some error messages for date/time types.
 Use all caps for type names within message.
Fix recently introduced side-effect bug disabling 'epoch' as a recognized
 field for date_part() etc. Reported by Peter E. (??)
Bump catalog version number.
Rename "microseconds" current transaction time field
 from ...Msec to ...Usec. Duh!
date/time regression tests updated for reference platform, but a few
 changes will be necessary for others.
parent 6254465d
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.111 2001/09/29 04:02:21 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.112 2001/10/18 17:30:03 thomas Exp $
*
* NOTES
* Transaction aborts can now occur two ways:
......@@ -378,7 +378,7 @@ GetCurrentTransactionStartTimeUsec(int *msec)
{
TransactionState s = CurrentTransactionState;
*msec = s->startTimeMsec;
*msec = s->startTimeUsec;
return s->startTime;
}
......@@ -877,7 +877,7 @@ StartTransaction(void)
#if NOT_USED
s->startTime = GetCurrentAbsoluteTime();
#endif
s->startTime = GetCurrentAbsoluteTimeUsec(&(s->startTimeMsec));
s->startTime = GetCurrentAbsoluteTimeUsec(&(s->startTimeUsec));
/*
* initialize the various transaction subsystems
......
This diff is collapsed.
......@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.157 2001/10/02 21:39:35 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.158 2001/10/18 17:30:14 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -2287,8 +2287,7 @@ _copyVariableSetStmt(VariableSetStmt *from)
if (from->name)
newnode->name = pstrdup(from->name);
if (from->value)
newnode->value = pstrdup(from->value);
Node_Copy(from, newnode, args);
return newnode;
}
......
......@@ -20,7 +20,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.105 2001/10/02 21:39:35 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.106 2001/10/18 17:30:14 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1159,7 +1159,7 @@ _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
{
if (!equalstr(a->name, b->name))
return false;
if (!equalstr(a->value, b->value))
if (!equal(a->args, b->args))
return false;
return true;
......
......@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.262 2001/10/10 00:02:42 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.263 2001/10/18 17:30:14 thomas Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
......@@ -58,6 +58,7 @@
#include "storage/lmgr.h"
#include "utils/acl.h"
#include "utils/numeric.h"
#include "utils/datetime.h"
#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
......@@ -82,6 +83,8 @@ static int pfunc_num_args;
static Node *makeA_Expr(int oper, char *opname, Node *lexpr, Node *rexpr);
static Node *makeTypeCast(Node *arg, TypeName *typename);
static Node *makeStringConst(char *str, TypeName *typename);
static Node *makeFloatConst(char *str);
static Node *makeRowExpr(char *opr, List *largs, List *rargs);
static void mapTargetColumns(List *source, List *target);
static SelectStmt *findLeftmostSelect(SelectStmt *node);
......@@ -92,6 +95,8 @@ static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
static Node *doNegate(Node *n);
static void doNegateFloat(Value *v);
#define MASK(b) (1 << (b))
%}
......@@ -209,7 +214,7 @@ static void doNegateFloat(Value *v);
%type <list> extract_list, position_list
%type <list> substr_list, trim_list
%type <list> opt_interval
%type <ival> opt_interval
%type <node> substr_from, substr_for
%type <boolean> opt_binary, opt_using, opt_instead, opt_cursor
......@@ -263,8 +268,9 @@ static void doNegateFloat(Value *v);
%type <ival> Iconst
%type <str> Sconst, comment_text
%type <str> UserId, opt_boolean, var_value, zone_value, ColId_or_Sconst
%type <str> UserId, opt_boolean, var_value, ColId_or_Sconst
%type <str> ColId, ColLabel, TokenId
%type <node> zone_value
%type <node> TableConstraint
%type <list> ColQualList
......@@ -757,49 +763,50 @@ VariableSetStmt: SET ColId TO var_value
{
VariableSetStmt *n = makeNode(VariableSetStmt);
n->name = $2;
n->value = $4;
n->args = makeList1(makeStringConst($4, NULL));
$$ = (Node *) n;
}
| SET ColId '=' var_value
{
VariableSetStmt *n = makeNode(VariableSetStmt);
n->name = $2;
n->value = $4;
n->args = makeList1(makeStringConst($4, NULL));
$$ = (Node *) n;
}
| SET TIME ZONE zone_value
{
VariableSetStmt *n = makeNode(VariableSetStmt);
n->name = "timezone";
n->value = $4;
if ($4 != NULL)
n->args = makeList1($4);
$$ = (Node *) n;
}
| SET TRANSACTION ISOLATION LEVEL opt_level
{
VariableSetStmt *n = makeNode(VariableSetStmt);
n->name = "XactIsoLevel";
n->value = $5;
n->args = makeList1(makeStringConst($5, NULL));
$$ = (Node *) n;
}
| SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL opt_level
{
VariableSetStmt *n = makeNode(VariableSetStmt);
n->name = "default_transaction_isolation";
n->value = $8;
n->args = makeList1(makeStringConst($8, NULL));
$$ = (Node *) n;
}
| SET NAMES opt_encoding
{
VariableSetStmt *n = makeNode(VariableSetStmt);
n->name = "client_encoding";
n->value = $3;
n->args = makeList1(makeStringConst($3, NULL));
$$ = (Node *) n;
}
| SET SESSION AUTHORIZATION ColId_or_Sconst
{
VariableSetStmt *n = makeNode(VariableSetStmt);
n->name = "session_authorization";
n->value = $4;
n->args = makeList1(makeStringConst($4, NULL));
$$ = (Node *) n;
}
;
......@@ -868,7 +875,47 @@ opt_boolean: TRUE_P { $$ = "true"; }
| OFF { $$ = "off"; }
;
zone_value: Sconst { $$ = $1; }
/* Timezone values can be:
* - a string such as 'pst8pdt'
* - an integer or floating point number
* - a time interval per SQL99
*/
zone_value: Sconst
{
$$ = makeStringConst($1, NULL);
}
| ConstInterval Sconst opt_interval
{
A_Const *n = (A_Const *) makeStringConst($2, $1);
n->typename->typmod = (($3 << 16) | 0xFFFF);
$$ = (Node *)n;
}
| ConstInterval '(' Iconst ')' Sconst opt_interval
{
A_Const *n = (A_Const *) makeStringConst($5, $1);
n->typename->typmod = (($3 << 16) | $6);
$$ = (Node *)n;
}
| FCONST
{
$$ = makeFloatConst($1);
}
| '-' FCONST
{
$$ = doNegate(makeFloatConst($2));
}
| ICONST
{
char buf[64];
sprintf(buf, "%d", $1);
$$ = makeFloatConst(pstrdup(buf));
}
| '-' ICONST
{
char buf[64];
sprintf(buf, "%d", $2);
$$ = doNegate(makeFloatConst(pstrdup(buf)));
}
| DEFAULT { $$ = NULL; }
| LOCAL { $$ = NULL; }
;
......@@ -3994,7 +4041,16 @@ opt_array_bounds: opt_array_bounds '[' ']'
;
SimpleTypename: ConstTypename
| ConstInterval
| ConstInterval opt_interval
{
$$ = $1;
$$->typmod = (($2 << 16) | 0xFFFF);
}
| ConstInterval '(' Iconst ')' opt_interval
{
$$ = $1;
$$->typmod = (($5 << 16) | $3);
}
;
ConstTypename: GenericType
......@@ -4267,7 +4323,10 @@ ConstDatetime: datetime
* - thomas 2001-09-06
*/
$$->timezone = $2;
$$->typmod = 0;
/* SQL99 specified a default precision of six.
* - thomas 2001-09-30
*/
$$->typmod = 6;
}
| TIME '(' Iconst ')' opt_timezone
{
......@@ -4295,7 +4354,7 @@ ConstDatetime: datetime
}
;
ConstInterval: INTERVAL opt_interval
ConstInterval: INTERVAL
{
$$ = makeNode(TypeName);
$$->name = xlateSqlType("interval");
......@@ -4326,15 +4385,20 @@ opt_timezone: WITH TIME ZONE { $$ = TRUE; }
| /*EMPTY*/ { $$ = FALSE; }
;
opt_interval: datetime { $$ = makeList1($1); }
| YEAR_P TO MONTH_P { $$ = NIL; }
| DAY_P TO HOUR_P { $$ = NIL; }
| DAY_P TO MINUTE_P { $$ = NIL; }
| DAY_P TO SECOND_P { $$ = NIL; }
| HOUR_P TO MINUTE_P { $$ = NIL; }
| HOUR_P TO SECOND_P { $$ = NIL; }
| MINUTE_P TO SECOND_P { $$ = NIL; }
| /*EMPTY*/ { $$ = NIL; }
opt_interval: YEAR_P { $$ = MASK(YEAR); }
| MONTH_P { $$ = MASK(MONTH); }
| DAY_P { $$ = MASK(DAY); }
| HOUR_P { $$ = MASK(HOUR); }
| MINUTE_P { $$ = MASK(MINUTE); }
| SECOND_P { $$ = MASK(SECOND); }
| YEAR_P TO MONTH_P { $$ = MASK(YEAR) | MASK(MONTH); }
| DAY_P TO HOUR_P { $$ = MASK(DAY) | MASK(HOUR); }
| DAY_P TO MINUTE_P { $$ = MASK(DAY) | MASK(HOUR) | MASK(MINUTE); }
| DAY_P TO SECOND_P { $$ = MASK(DAY) | MASK(HOUR) | MASK(MINUTE) | MASK(SECOND); }
| HOUR_P TO MINUTE_P { $$ = MASK(HOUR) | MASK(MINUTE); }
| HOUR_P TO SECOND_P { $$ = MASK(HOUR) | MASK(MINUTE) | MASK(SECOND); }
| MINUTE_P TO SECOND_P { $$ = MASK(MINUTE) | MASK(SECOND); }
| /*EMPTY*/ { $$ = -1; }
;
......@@ -5561,6 +5625,16 @@ AexprConst: Iconst
n->typename = $1;
n->val.type = T_String;
n->val.val.str = $2;
n->typename->typmod = (($3 << 16) | 0xFFFF);
$$ = (Node *)n;
}
| ConstInterval '(' Iconst ')' Sconst opt_interval
{
A_Const *n = makeNode(A_Const);
n->typename = $1;
n->val.type = T_String;
n->val.val.str = $5;
n->typename->typmod = (($6 << 16) | $3);
$$ = (Node *)n;
}
| ParamNo
......@@ -5616,7 +5690,6 @@ UserId: ColId { $$ = $1; };
ColId: IDENT { $$ = $1; }
| datetime { $$ = $1; }
| TokenId { $$ = $1; }
| INTERVAL { $$ = "interval"; }
| NATIONAL { $$ = "national"; }
| NONE { $$ = "none"; }
| PATH_P { $$ = "path"; }
......@@ -5818,12 +5891,13 @@ ColLabel: ColId { $$ = $1; }
| GROUP { $$ = "group"; }
| HAVING { $$ = "having"; }
| ILIKE { $$ = "ilike"; }
| INITIALLY { $$ = "initially"; }
| IN { $$ = "in"; }
| INITIALLY { $$ = "initially"; }
| INNER_P { $$ = "inner"; }
| INOUT { $$ = "inout"; }
| INTERSECT { $$ = "intersect"; }
| INTERVAL { $$ = "interval"; }
| INTO { $$ = "into"; }
| INOUT { $$ = "inout"; }
| IS { $$ = "is"; }
| ISNULL { $$ = "isnull"; }
| JOIN { $$ = "join"; }
......@@ -5947,6 +6021,31 @@ makeTypeCast(Node *arg, TypeName *typename)
}
}
static Node *
makeStringConst(char *str, TypeName *typename)
{
A_Const *n = makeNode(A_Const);
n->val.type = T_String;
n->val.val.str = str;
n->typename = typename;
return (Node *)n;
}
static Node *
makeFloatConst(char *str)
{
A_Const *n = makeNode(A_Const);
TypeName *t = makeNode(TypeName);
n->val.type = T_Float;
n->val.val.str = str;
t->name = xlateSqlType("float");
t->typmod = -1;
n->typename = t;
return (Node *)n;
}
/* makeRowExpr()
* Generate separate operator nodes for a single row descriptor expression.
* Perhaps this should go deeper in the parser someday...
......
......@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.120 2001/10/12 00:07:14 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.121 2001/10/18 17:30:15 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -740,7 +740,7 @@ ProcessUtility(Node *parsetree,
{
VariableSetStmt *n = (VariableSetStmt *) parsetree;
SetPGVariable(n->name, n->value);
SetPGVariable(n->name, n->args);
set_ps_display(commandTag = "SET VARIABLE");
}
break;
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.61 2001/10/04 15:14:22 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.62 2001/10/18 17:30:15 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1458,6 +1458,117 @@ text_timetz(PG_FUNCTION_ARGS)
Int32GetDatum(-1));
}
/* timetz_part()
* Extract specified field from time type.
*/
Datum
timetz_part(PG_FUNCTION_ARGS)
{
text *units = PG_GETARG_TEXT_P(0);
TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
float8 result;
int type,
val;
int i;
char *up,
*lp,
lowunits[MAXDATELEN + 1];
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "TIMETZ units '%s' not recognized",
DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units))));
up = VARDATA(units);
lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
*lp++ = tolower((unsigned char) *up++);
*lp = '\0';
type = DecodeUnits(0, lowunits, &val);
if (type == UNKNOWN_FIELD)
type = DecodeSpecial(0, lowunits, &val);
if (type == UNITS)
{
double trem;
double dummy;
int tz;
double fsec;
struct tm tt,
*tm = &tt;
trem = time->time;
TMODULO(trem, tm->tm_hour, 3600e0);
TMODULO(trem, tm->tm_min, 60e0);
TMODULO(trem, tm->tm_sec, 1e0);
fsec = trem;
tz = time->zone;
switch (val)
{
case DTK_TZ:
result = tz;
break;
case DTK_TZ_MINUTE:
result = tz / 60;
TMODULO(result, dummy, 60e0);
break;
case DTK_TZ_HOUR:
dummy = tz;
TMODULO(dummy, result, 3600e0);
break;
case DTK_MICROSEC:
result = ((tm->tm_sec + fsec) * 1000000);
break;
case DTK_MILLISEC:
result = ((tm->tm_sec + fsec) * 1000);
break;
case DTK_SECOND:
result = (tm->tm_sec + fsec);
break;
case DTK_MINUTE:
result = tm->tm_min;
break;
case DTK_HOUR:
result = tm->tm_hour;
break;
case DTK_DAY:
case DTK_MONTH:
case DTK_QUARTER:
case DTK_YEAR:
case DTK_DECADE:
case DTK_CENTURY:
case DTK_MILLENNIUM:
default:
elog(ERROR, "TIMETZ units '%s' not supported",
DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units))));
result = 0;
}
}
else if ((type == RESERV) && (val == DTK_EPOCH))
{
result = time->time - time->zone;
}
else
{
elog(ERROR, "TIMETZ units '%s' not recognized",
DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units))));
result = 0;
}
PG_RETURN_FLOAT8(result);
}
/* timetz_zone()
* Encode time with time zone type with specified time zone.
*/
......
This diff is collapsed.
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.87 2001/10/01 02:31:33 ishii Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.88 2001/10/18 17:30:15 thomas Exp $
*
* NOTES
*
......@@ -113,7 +113,7 @@ static int istinterval(char *i_string,
/* GetCurrentAbsoluteTime()
* Get the current system time. Set timezone parameters if not specified elsewhere.
* Define HasTZSet to allow clients to specify the default timezone.
* Define HasCTZSet to allow clients to specify the default timezone.
*
* Returns the number of seconds since epoch (January 1 1970 GMT)
*/
......@@ -173,7 +173,7 @@ GetCurrentAbsoluteTime(void)
*/
strftime(CTZName, MAXTZLEN, "%Z", localtime(&now));
#endif
};
}
return (AbsoluteTime) now;
} /* GetCurrentAbsoluteTime() */
......@@ -181,7 +181,7 @@ GetCurrentAbsoluteTime(void)
/* GetCurrentAbsoluteTime()
* Get the current system time. Set timezone parameters if not specified elsewhere.
* Define HasTZSet to allow clients to specify the default timezone.
* Define HasCTZSet to allow clients to specify the default timezone.
*
* Returns the number of seconds since epoch (January 1 1970 GMT)
*/
......@@ -284,7 +284,7 @@ GetCurrentTimeUsec(struct tm *tm, double *fsec)
void
abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char *tzn)
abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
{
time_t time = (time_t) _time;
......@@ -297,9 +297,15 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char *tzn)
ftime(&tb);
#endif
/* If HasCTZSet is true then we have a brute force time zone specified.
* Go ahead and rotate to the local time zone since we will later bypass
* any calls which adjust the tm fields.
*/
if (HasCTZSet && (tzp != NULL))
time -= CTimeZone;
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
if (tzp != NULL)
if ((! HasCTZSet) && (tzp != NULL))
{
tx = localtime((time_t *) &time);
#ifdef NO_MKTIME_BEFORE_1970
......@@ -329,47 +335,95 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char *tzn)
tm->tm_zone = tx->tm_zone;
if (tzp != NULL)
*tzp = -tm->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
/* XXX FreeBSD man pages indicate that this should work - tgl 97/04/23 */
if (tzn != NULL)
{
/*
* Copy no more than MAXTZLEN bytes of timezone to tzn, in case it
* contains an error message, which doesn't fit in the buffer
/* We have a brute force time zone per SQL99?
* Then use it without change
* since we have already rotated to the time zone.
*/
StrNCpy(tzn, tm->tm_zone, MAXTZLEN + 1);
if (strlen(tm->tm_zone) > MAXTZLEN)
elog(NOTICE, "Invalid timezone \'%s\'", tm->tm_zone);
if (HasCTZSet)
{
*tzp = CTimeZone;
tm->tm_gmtoff = CTimeZone;
tm->tm_isdst = -1;
tm->tm_zone = NULL;
if (tzn != NULL)
*tzn = NULL;
}
else
{
*tzp = -tm->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
/* XXX FreeBSD man pages indicate that this should work - tgl 97/04/23 */
if (tzn != NULL)
{
/*
* Copy no more than MAXTZLEN bytes of timezone to tzn, in case it
* contains an error message, which doesn't fit in the buffer
*/
StrNCpy(*tzn, tm->tm_zone, MAXTZLEN + 1);
if (strlen(tm->tm_zone) > MAXTZLEN)
elog(NOTICE, "Invalid timezone \'%s\'", tm->tm_zone);
}
}
}
#elif defined(HAVE_INT_TIMEZONE)
if (tzp != NULL)
*tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
if (tzn != NULL)
{
/*
* Copy no more than MAXTZLEN bytes of timezone to tzn, in case it
* contains an error message, which doesn't fit in the buffer
/* We have a brute force time zone per SQL99?
* Then use it without change
* since we have already rotated to the time zone.
*/
StrNCpy(tzn, tzname[tm->tm_isdst], MAXTZLEN + 1);
if (strlen(tzname[tm->tm_isdst]) > MAXTZLEN)
elog(NOTICE, "Invalid timezone \'%s\'", tzname[tm->tm_isdst]);
if (HasCTZSet)
{
*tzp = CTimeZone;
tm->tm_isdst = -1;
if (tzn != NULL)
*tzn = NULL;
}
else
{
*tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
if (tzn != NULL)
{
/*
* Copy no more than MAXTZLEN bytes of timezone to tzn, in case it
* contains an error message, which doesn't fit in the buffer
*/
StrNCpy(*tzn, tzname[tm->tm_isdst], MAXTZLEN + 1);
if (strlen(tzname[tm->tm_isdst]) > MAXTZLEN)
elog(NOTICE, "Invalid timezone \'%s\'", tzname[tm->tm_isdst]);
}
}
}
#endif
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
if (tzp != NULL)
*tzp = tb.timezone * 60;
/*
* XXX does this work to get the local timezone string in V7? - tgl
* 97/03/18
*/
if (tzn != NULL)
{
strftime(tzn, MAXTZLEN, "%Z", localtime(&now));
tzn[MAXTZLEN] = '\0'; /* let's just be sure it's null-terminated */
/* We have a brute force time zone per SQL99?
* Then use it without change
* since we have already rotated to the time zone.
*/
if (HasCTZSet)
{
*tzp = CTimeZone;
if (tzn != NULL)
*tzn = NULL;
}
else
{
*tzp = tb.timezone * 60;
/*
* XXX does this work to get the local timezone string in V7? - tgl
* 97/03/18
*/
if (tzn != NULL)
{
strftime(*tzn, MAXTZLEN, "%Z", localtime(&now));
tzn[MAXTZLEN] = '\0'; /* let's just be sure it's null-terminated */
}
}
}
#endif
......@@ -508,7 +562,7 @@ nabstimeout(PG_FUNCTION_ARGS)
strcpy(buf, EARLY);
break;
default:
abstime2tm(time, &tz, tm, tzn);
abstime2tm(time, &tz, tm, &tzn);
EncodeDateTime(tm, fsec, &tz, &tzn, DateStyle, buf);
break;
}
......@@ -676,7 +730,8 @@ abstime_timestamp(PG_FUNCTION_ARGS)
struct tm tt,
*tm = &tt;
int tz;
char tzn[MAXTZLEN];
char zone[MAXDATELEN + 1],
*tzn = zone;
switch (abstime)
{
......@@ -694,7 +749,7 @@ abstime_timestamp(PG_FUNCTION_ARGS)
break;
default:
abstime2tm(abstime, &tz, tm, tzn);
abstime2tm(abstime, &tz, tm, &tzn);
result = abstime + ((date2j(1970, 1, 1) - date2j(2000, 1, 1)) * 86400) + tz;
break;
};
......
This diff is collapsed.
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: xact.h,v 1.37 2001/09/28 08:09:12 thomas Exp $
* $Id: xact.h,v 1.38 2001/10/18 17:30:15 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -40,7 +40,7 @@ typedef struct TransactionStateData
CommandId commandId;
CommandId scanCommandId;
AbsoluteTime startTime;
int startTimeMsec;
int startTimeUsec;
int state;
int blockState;
} TransactionStateData;
......
......@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: catversion.h,v 1.98 2001/10/03 17:22:05 tgl Exp $
* $Id: catversion.h,v 1.99 2001/10/18 17:30:15 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
#define CATALOG_VERSION_NO 200110031
#define CATALOG_VERSION_NO 200110181
#endif
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_proc.h,v 1.216 2001/10/12 02:08:34 ishii Exp $
* $Id: pg_proc.h,v 1.217 2001/10/18 17:30:15 thomas Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
......@@ -1434,7 +1434,6 @@ DATA(insert OID = 1171 ( date_part PGUID 12 f t f t 2 f 701 "25 1184" 100
DESCR("extract field from timestamp with time zone");
DATA(insert OID = 1172 ( date_part PGUID 12 f t t t 2 f 701 "25 1186" 100 0 0 100 interval_part - ));
DESCR("extract field from interval");
DATA(insert OID = 1173 ( timestamptz PGUID 12 f t f t 1 f 1184 "702" 100 0 0 100 abstime_timestamptz - ));
DESCR("convert abstime to timestamp with time zone");
DATA(insert OID = 1174 ( timestamptz PGUID 12 f t f t 1 f 1184 "1082" 100 0 0 100 date_timestamptz - ));
......@@ -1523,7 +1522,8 @@ DATA(insert OID = 1271 ( overlaps PGUID 12 f t t f 4 f 16 "1266 1266 1266 1
DESCR("SQL92 interval comparison");
DATA(insert OID = 1272 ( datetime_pl PGUID 12 f t t t 2 f 1114 "1082 1083" 100 0 0 100 datetime_timestamp - ));
DESCR("convert date and time to timestamp");
DATA(insert OID = 1273 ( date_part PGUID 12 f t t t 2 f 701 "25 1266" 100 0 0 100 timetz_part - ));
DESCR("extract field from time with time zone");
DATA(insert OID = 1274 ( int84pl PGUID 12 f t t t 2 f 20 "20 23" 100 0 0 100 int84pl - ));
DESCR("add");
DATA(insert OID = 1275 ( int84mi PGUID 12 f t t t 2 f 20 "20 23" 100 0 0 100 int84mi - ));
......@@ -1709,11 +1709,11 @@ DESCR("length");
DATA(insert OID = 1382 ( date_part PGUID 14 f t f t 2 f 701 "25 702" 100 0 0 100 "select date_part($1, timestamptz($2))" - ));
DESCR("extract field from abstime");
DATA(insert OID = 1383 ( date_part PGUID 14 f t f t 2 f 701 "25 703" 100 0 0 100 "select date_part($1, interval($2))" - ));
DATA(insert OID = 1383 ( date_part PGUID 14 f t f t 2 f 701 "25 703" 100 0 0 100 "select date_part($1, cast($2 as interval))" - ));
DESCR("extract field from reltime");
DATA(insert OID = 1384 ( date_part PGUID 14 f t t t 2 f 701 "25 1082" 100 0 0 100 "select date_part($1, cast($2 as timestamp without time zone))" - ));
DESCR("extract field from date");
DATA(insert OID = 1385 ( date_part PGUID 14 f t t t 2 f 701 "25 1083" 100 0 0 100 "select date_part($1, interval($2))" - ));
DATA(insert OID = 1385 ( date_part PGUID 14 f t t t 2 f 701 "25 1083" 100 0 0 100 "select date_part($1, cast($2 as time with time zone))" - ));
DESCR("extract field from time");
DATA(insert OID = 1386 ( age PGUID 14 f t f t 1 f 1186 "1184" 100 0 0 100 "select age(cast(current_date as timestamp with time zone), $1)" - ));
DESCR("date difference from today preserving months and years");
......
......@@ -2,13 +2,13 @@
* Headers for handling of 'SET var TO', 'SHOW var' and 'RESET var'
* statements
*
* $Id: variable.h,v 1.13 2000/10/26 17:31:33 tgl Exp $
* $Id: variable.h,v 1.14 2001/10/18 17:30:16 thomas Exp $
*
*/
#ifndef VARIABLE_H
#define VARIABLE_H
extern void SetPGVariable(const char *name, const char *value);
extern void SetPGVariable(const char *name, List *args);
extern void GetPGVariable(const char *name);
extern void ResetPGVariable(const char *name);
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: parsenodes.h,v 1.146 2001/10/12 00:07:15 tgl Exp $
* $Id: parsenodes.h,v 1.147 2001/10/18 17:30:16 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -736,7 +736,7 @@ typedef struct VariableSetStmt
{
NodeTag type;
char *name;
char *value;
List *args;
} VariableSetStmt;
/* ----------------------
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: date.h,v 1.13 2001/10/03 05:29:25 thomas Exp $
* $Id: date.h,v 1.14 2001/10/18 17:30:16 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -118,6 +118,7 @@ extern Datum timestamptz_timetz(PG_FUNCTION_ARGS);
extern Datum datetimetz_timestamptz(PG_FUNCTION_ARGS);
extern Datum text_timetz(PG_FUNCTION_ARGS);
extern Datum timetz_text(PG_FUNCTION_ARGS);
extern Datum timetz_part(PG_FUNCTION_ARGS);
extern Datum timetz_zone(PG_FUNCTION_ARGS);
extern Datum timetz_izone(PG_FUNCTION_ARGS);
extern Datum timetz_pl_interval(PG_FUNCTION_ARGS);
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: nabstime.h,v 1.31 2001/09/28 08:09:14 thomas Exp $
* $Id: nabstime.h,v 1.32 2001/10/18 17:30:16 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -158,6 +158,6 @@ extern Datum timeofday(PG_FUNCTION_ARGS);
/* non-fmgr-callable support routines */
extern AbsoluteTime GetCurrentAbsoluteTime(void);
extern AbsoluteTime GetCurrentAbsoluteTimeUsec(int *usec);
extern void abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn);
extern void abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char **tzn);
#endif /* NABSTIME_H */
......@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: timestamp.h,v 1.20 2001/10/03 15:42:12 tgl Exp $
* $Id: timestamp.h,v 1.21 2001/10/18 17:30:16 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -105,6 +105,7 @@ extern Datum timestamp_larger(PG_FUNCTION_ARGS);
extern Datum interval_in(PG_FUNCTION_ARGS);
extern Datum interval_out(PG_FUNCTION_ARGS);
extern Datum interval_scale(PG_FUNCTION_ARGS);
extern Datum interval_eq(PG_FUNCTION_ARGS);
extern Datum interval_ne(PG_FUNCTION_ARGS);
extern Datum interval_lt(PG_FUNCTION_ARGS);
......
......@@ -1788,8 +1788,8 @@ convert_escape(char *value)
mapFunc = mapFunction(key);
/*
* We could have mapFunction() return key if not in table... -
* thomas 2000-04-03
* We could have mapFunction() return key if not in table...
* - thomas 2000-04-03
*/
if (mapFunc == NULL)
{
......
......@@ -1310,9 +1310,9 @@ SELECT '' AS "16", f1 AS "timestamp"
| Sat Sep 22 18:19:20 2001 PDT
(16 rows)
SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS interval, d.f1 + t.f1 AS plus
SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS "interval", d.f1 + t.f1 AS plus
FROM TEMP_TIMESTAMP d, INTERVAL_TBL t
ORDER BY plus, "timestamp", interval;
ORDER BY plus, "timestamp", "interval";
160 | timestamp | interval | plus
-----+------------------------------+-------------------------------+------------------------------
| Thu Jan 01 00:00:00 1970 PST | @ 14 secs ago | Wed Dec 31 23:59:46 1969 PST
......@@ -1477,10 +1477,10 @@ SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS interval, d.f1 + t.f1 AS plus
| Sat Sep 22 18:19:20 2001 PDT | @ 34 years | Sat Sep 22 18:19:20 2035 PDT
(160 rows)
SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS interval, d.f1 - t.f1 AS minus
SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS "interval", d.f1 - t.f1 AS minus
FROM TEMP_TIMESTAMP d, INTERVAL_TBL t
WHERE isfinite(d.f1)
ORDER BY minus, "timestamp", interval;
ORDER BY minus, "timestamp", "interval";
160 | timestamp | interval | minus
-----+------------------------------+-------------------------------+------------------------------
| Thu Jan 01 00:00:00 1970 PST | @ 34 years | Wed Jan 01 00:00:00 1936 PST
......@@ -2084,7 +2084,7 @@ SELECT '' AS ten, f1 AS interval, reltime(f1) AS reltime
| @ 5 mons 12 hours | @ 5 mons 12 hours
(10 rows)
SELECT '' AS six, f1 as reltime, interval(f1) AS interval
SELECT '' AS six, f1 as reltime, CAST(f1 AS interval) AS interval
FROM RELTIME_TBL;
six | reltime | interval
-----+---------------+---------------
......
......@@ -59,7 +59,7 @@ INSERT INTO TIMESTAMP_TBL VALUES ('infinity');
INSERT INTO TIMESTAMP_TBL VALUES ('epoch');
-- Obsolete special values
INSERT INTO TIMESTAMP_TBL VALUES ('invalid');
ERROR: Timestamp 'invalid' no longer supported
ERROR: TIMESTAMP 'invalid' no longer supported
-- Postgres v6.0 standard output format
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Invalid Abstime');
......@@ -137,7 +137,7 @@ INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 2001');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 -0097');
ERROR: Bad timestamp external representation 'Feb 16 17:32:01 -0097'
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 5097 BC');
ERROR: Timestamp out of range 'Feb 16 17:32:01 5097 BC'
ERROR: TIMESTAMP out of range 'Feb 16 17:32:01 5097 BC'
SELECT '' AS "64", d1 FROM TIMESTAMP_TBL;
64 | d1
----+-----------------------------
......
......@@ -54,7 +54,7 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('infinity');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('epoch');
-- Obsolete special values
INSERT INTO TIMESTAMPTZ_TBL VALUES ('invalid');
ERROR: Timestamp with time zone 'invalid' no longer supported
ERROR: TIMESTAMP WITH TIME ZONE 'invalid' no longer supported
-- Postgres v6.0 standard output format
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Invalid Abstime');
......@@ -132,7 +132,7 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('Jan 01 17:32:01 2001');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 -0097');
ERROR: Bad timestamp external representation 'Feb 16 17:32:01 -0097'
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 5097 BC');
ERROR: Timestamp out of range 'Feb 16 17:32:01 5097 BC'
ERROR: TIMESTAMP WITH TIME ZONE out of range 'Feb 16 17:32:01 5097 BC'
SELECT '' AS "64", d1 FROM TIMESTAMPTZ_TBL;
64 | d1
----+---------------------------------
......
......@@ -177,14 +177,14 @@ SELECT '' AS "16", f1 AS "timestamp"
FROM TEMP_TIMESTAMP
ORDER BY "timestamp";
SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS interval, d.f1 + t.f1 AS plus
SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS "interval", d.f1 + t.f1 AS plus
FROM TEMP_TIMESTAMP d, INTERVAL_TBL t
ORDER BY plus, "timestamp", interval;
ORDER BY plus, "timestamp", "interval";
SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS interval, d.f1 - t.f1 AS minus
SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS "interval", d.f1 - t.f1 AS minus
FROM TEMP_TIMESTAMP d, INTERVAL_TBL t
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,
d.f1 - timestamp '1980-01-06 00:00 GMT' AS difference
......@@ -250,7 +250,7 @@ SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp"
SELECT '' AS ten, f1 AS interval, reltime(f1) AS reltime
FROM INTERVAL_TBL;
SELECT '' AS six, f1 as reltime, interval(f1) AS interval
SELECT '' AS six, f1 as reltime, CAST(f1 AS interval) AS interval
FROM RELTIME_TBL;
DROP TABLE TEMP_TIMESTAMP;
......
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