Commit 3e1beda2 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Implement precision support for timestamp and time, both with and without

 time zones.
SQL99 spec requires a default of zero (round to seconds) which is set
 in gram.y as typmod is set in the parse tree. We *could* change to a
 default of either 6 (for internal compatibility with previous versions)
 or 2 (for external compatibility with previous versions).
Evaluate entries in pg_proc wrt the iscachable attribute for timestamp and
 other date/time types. Try to recognize cases where side effects like the
 current time zone setting may have an effect on results to decide whether
 something is cachable or not.
parent a51de40f
......@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.198 2001/09/07 21:57:53 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.199 2001/10/03 05:29:12 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -510,8 +510,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
* No user-supplied value, so add a targetentry with DEFAULT
* expr and correct data for the target column.
*/
te = makeTargetEntry(
makeResdom(attrno,
te = makeTargetEntry(makeResdom(attrno,
thisatt->atttypid,
thisatt->atttypmod,
pstrdup(NameStr(thisatt->attname)),
......
......@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.256 2001/10/02 21:39:35 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.257 2001/10/03 05:29:12 thomas Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
......@@ -4163,7 +4163,7 @@ bit: BIT opt_varying
* SQL92 character data types
* The following implements CHAR() and VARCHAR().
*/
Character: character '(' Iconst ')'
Character: character '(' Iconst ')' opt_charset
{
$$ = makeNode(TypeName);
$$->name = $1;
......@@ -4180,34 +4180,37 @@ Character: character '(' Iconst ')'
* truncate where necessary)
*/
$$->typmod = VARHDRSZ + $3;
if (($5 != NULL) && (strcmp($5, "sql_text") != 0)) {
char *type;
type = palloc(strlen($$->name) + 1 + strlen($5) + 1);
strcpy(type, $$->name);
strcat(type, "_");
strcat(type, $5);
$$->name = xlateSqlType(type);
};
}
| character
| character opt_charset
{
$$ = makeNode(TypeName);
$$->name = $1;
/* default length, if needed, will be inserted later */
$$->typmod = -1;
}
;
character: CHARACTER opt_varying opt_charset
{
char *type, *c;
if (($3 == NULL) || (strcmp($3, "sql_text") == 0)) {
if ($2) type = xlateSqlType("varchar");
else type = xlateSqlType("bpchar");
} else {
if ($2) {
c = palloc(strlen("var") + strlen($3) + 1);
strcpy(c, "var");
strcat(c, $3);
type = xlateSqlType(c);
} else {
type = xlateSqlType($3);
}
if (($2 != NULL) && (strcmp($2, "sql_text") != 0)) {
char *type;
type = palloc(strlen($$->name) + 1 + strlen($2) + 1);
strcpy(type, $$->name);
strcat(type, "_");
strcat(type, $2);
$$->name = xlateSqlType(type);
};
$$ = type;
}
;
character: CHARACTER opt_varying { $$ = xlateSqlType($2 ? "varchar": "bpchar"); }
| CHAR opt_varying { $$ = xlateSqlType($2 ? "varchar": "bpchar"); }
| VARCHAR { $$ = xlateSqlType("varchar"); }
| NATIONAL CHARACTER opt_varying { $$ = xlateSqlType($3 ? "varchar": "bpchar"); }
......@@ -4233,6 +4236,22 @@ ConstDatetime: datetime
$$->name = xlateSqlType($1);
$$->typmod = -1;
}
| TIMESTAMP '(' Iconst ')' opt_timezone_x
{
$$ = makeNode(TypeName);
if ($5)
$$->name = xlateSqlType("timestamptz");
else
$$->name = xlateSqlType("timestamp");
/* XXX the timezone field seems to be unused
* - thomas 2001-09-06
*/
$$->timezone = $5;
if (($3 < 0) || ($3 > 13))
elog(ERROR,"TIMESTAMP %s precision %d must be beween 0 and %d",
($5? " WITH TIME ZONE": ""), 0, 13);
$$->typmod = $3;
}
| TIMESTAMP opt_timezone_x
{
$$ = makeNode(TypeName);
......@@ -4244,7 +4263,19 @@ ConstDatetime: datetime
* - thomas 2001-09-06
*/
$$->timezone = $2;
$$->typmod = -1;
$$->typmod = 0;
}
| TIME '(' Iconst ')' opt_timezone
{
$$ = makeNode(TypeName);
if ($5)
$$->name = xlateSqlType("timetz");
else
$$->name = xlateSqlType("time");
if (($3 < 0) || ($3 > 13))
elog(ERROR,"TIME %s precision %d must be beween 0 and %d",
($5? " WITH TIME ZONE": ""), 0, 13);
$$->typmod = $3;
}
| TIME opt_timezone
{
......@@ -4253,7 +4284,10 @@ ConstDatetime: datetime
$$->name = xlateSqlType("timetz");
else
$$->name = xlateSqlType("time");
$$->typmod = -1;
/* SQL99 specified a default precision of zero.
* - thomas 2001-09-30
*/
$$->typmod = 0;
}
;
......@@ -5586,8 +5620,6 @@ ColId: IDENT { $$ = $1; }
| NATIONAL { $$ = "national"; }
| NONE { $$ = "none"; }
| PATH_P { $$ = "path"; }
| TIME { $$ = "time"; }
| TIMESTAMP { $$ = "timestamp"; }
;
/* Parser tokens to be used as identifiers.
......@@ -5839,6 +5871,8 @@ ColLabel: ColId { $$ = $1; }
| SUBSTRING { $$ = "substring"; }
| TABLE { $$ = "table"; }
| THEN { $$ = "then"; }
| TIME { $$ = "time"; }
| TIMESTAMP { $$ = "timestamp"; }
| TO { $$ = "to"; }
| TRAILING { $$ = "trailing"; }
| TRANSACTION { $$ = "transaction"; }
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.61 2001/09/28 08:09:09 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.62 2001/10/03 05:29:12 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -287,8 +287,7 @@ coerce_type_typmod(ParseState *pstate, Node *node,
* We assume that only typmod values greater than 0 indicate a forced
* conversion is necessary.
*/
if (atttypmod <= 0 ||
atttypmod == exprTypmod(node))
if ((atttypmod <= 0) || (atttypmod == exprTypmod(node)))
return node;
funcname = typeidTypeName(targetTypeId);
......@@ -376,9 +375,9 @@ select_common_type(List *typeids, const char *context)
Oid ntype = (Oid) lfirsti(l);
/* move on to next one if no new information... */
if (ntype && (ntype != UNKNOWNOID) && (ntype != ptype))
if ((ntype != InvalidOid) && (ntype != UNKNOWNOID) && (ntype != ptype))
{
if (!ptype || ptype == UNKNOWNOID)
if ((ptype == InvalidOid) || ptype == UNKNOWNOID)
{
/* so far, only nulls so take anything... */
ptype = ntype;
......@@ -456,6 +455,9 @@ coerce_to_common_type(ParseState *pstate, Node *node,
/* TypeCategory()
* Assign a category to the specified OID.
* XXX This should be moved to system catalog lookups
* to allow for better type extensibility.
* - thomas 2001-09-30
*/
CATEGORY
TypeCategory(Oid inType)
......@@ -538,16 +540,22 @@ TypeCategory(Oid inType)
/* IsPreferredType()
* Check if this type is a preferred type.
* XXX This should be moved to system catalog lookups
* to allow for better type extensibility.
* - thomas 2001-09-30
*/
bool
IsPreferredType(CATEGORY category, Oid type)
{
return type == PreferredType(category, type);
return (type == PreferredType(category, type));
} /* IsPreferredType() */
/* PreferredType()
* Return the preferred type OID for the specified category.
* XXX This should be moved to system catalog lookups
* to allow for better type extensibility.
* - thomas 2001-09-30
*/
static Oid
PreferredType(CATEGORY category, Oid type)
......@@ -603,210 +611,3 @@ PreferredType(CATEGORY category, Oid type)
}
return result;
} /* PreferredType() */
#ifdef NOT_USED
Oid
PromoteTypeToNext(Oid inType)
{
Oid result;
switch (inType)
{
case (CHAROID):
case (BPCHAROID):
result = VARCHAROID;
break;
case (VARCHAROID):
result = TEXTOID;
break;
case (INT2OID):
case (CASHOID):
result = INT4OID;
break;
case (INT4OID):
case (INT8OID):
case (FLOAT4OID):
result = FLOAT8OID;
break;
case (NUMERICOID):
result = NUMERICOID;
break;
case (DATEOID):
result = TIMESTAMPOID;
break;
case (ABSTIMEOID):
case (TIMESTAMPOID):
result = TIMESTAMPTZOID;
break;
case (TIMEOID):
case (RELTIMEOID):
result = INTERVALOID;
break;
case (BOOLOID):
case (TEXTOID):
case (FLOAT8OID):
case (TIMESTAMPTZOID):
case (INTERVALOID):
default:
result = inType;
break;
}
return result;
} /* PromoteTypeToNext() */
Oid
DemoteType(Oid inType)
{
Oid result;
switch (inType)
{
case (FLOAT4OID):
case (FLOAT8OID):
result = INT4OID;
break;
default:
result = inType;
break;
}
return result;
} /* DemoteType() */
Oid
PromoteLesserType(Oid inType1, Oid inType2, Oid *newType1, Oid *newType2)
{
Oid result;
if (inType1 == inType2)
{
result = PromoteTypeToNext(inType1);
inType1 = result;
*arg2 = result;
return result;
}
kind1 = ClassifyType(inType1);
kind2 = ClassifyType(*arg2);
if (kind1 != kind2)
{
*newType1 = inType1;
*newType2 = inType2;
result = InvalidOid;
}
isBuiltIn1 = IS_BUILTIN_TYPE(inType1);
isBuiltIn2 = IS_BUILTIN_TYPE(*arg2);
if (isBuiltIn1 && isBuiltIn2)
{
switch (*arg1)
{
case (CHAROID):
switch (*arg2)
{
case (BPCHAROID):
case (VARCHAROID):
case (TEXTOID):
case (INT2OID):
case (INT4OID):
case (FLOAT4OID):
case (FLOAT8OID):
case (CASHOID):
case (POINTOID):
case (LSEGOID):
case (LINEOID):
case (BOXOID):
case (PATHOID):
case (CIRCLEOID):
case (POLYGONOID):
case (InvalidOid):
case (UNKNOWNOID):
case (BOOLOID):
default:
*arg1 = InvalidOid;
*arg2 = InvalidOid;
result = InvalidOid;
}
}
}
else if (isBuiltIn1 && !isBuiltIn2)
{
if ((promotedType = PromoteBuiltInType(*arg1)) != *arg1)
{
*arg1 = promotedType;
return promotedType;
}
else if (CanCoerceType(*arg1, *arg2))
{
*arg1 = *arg2;
return *arg2;
}
}
else if (!isBuiltIn1 && isBuiltIn2)
{
if ((promotedType = PromoteBuiltInType(*arg2)) != *arg2)
{
*arg2 = promotedType;
return promotedType;
}
else if (CanCoerceType(*arg2, *arg1))
{
*arg2 = *arg1;
return *arg1;
}
}
if (*arg2 == InvalidOid)
return InvalidOid;
switch (*arg1)
{
case (CHAROID):
switch (*arg2)
{
case (BPCHAROID):
case (VARCHAROID):
case (TEXTOID):
case (INT2OID):
case (INT4OID):
case (FLOAT4OID):
case (FLOAT8OID):
case (CASHOID):
case (POINTOID):
case (LSEGOID):
case (LINEOID):
case (BOXOID):
case (PATHOID):
case (CIRCLEOID):
case (POLYGONOID):
case (InvalidOid):
case (UNKNOWNOID):
case (BOOLOID):
default:
*arg1 = InvalidOid;
*arg2 = InvalidOid;
result = InvalidOid;
}
}
}
#endif
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.58 2001/09/28 08:09:10 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.59 2001/10/03 05:29:24 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -28,6 +28,9 @@
#include "utils/timestamp.h"
static void
AdjustTimeForTypmod(TimeADT *time, int32 typmod);
/*****************************************************************************
* Date ADT
*****************************************************************************/
......@@ -425,7 +428,11 @@ Datum
time_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
TimeADT time;
#ifdef NOT_USED
Oid typelem = PG_GETARG_OID(1);
#endif
int32 typmod = PG_GETARG_INT32(2);
TimeADT result;
double fsec;
struct tm tt,
*tm = &tt;
......@@ -439,9 +446,11 @@ time_in(PG_FUNCTION_ARGS)
|| (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, NULL) != 0))
elog(ERROR, "Bad time external representation '%s'", str);
time = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
AdjustTimeForTypmod(&result, typmod);
PG_RETURN_TIMEADT(time);
PG_RETURN_TIMEADT(result);
}
Datum
......@@ -452,13 +461,14 @@ time_out(PG_FUNCTION_ARGS)
struct tm tt,
*tm = &tt;
double fsec;
double trem;
char buf[MAXDATELEN + 1];
tm->tm_hour = (time / (60 * 60));
tm->tm_min = (((int) (time / 60)) % 60);
tm->tm_sec = (((int) time) % 60);
fsec = 0;
trem = time;
TMODULO(trem, tm->tm_hour, 3600e0);
TMODULO(trem, tm->tm_min, 60e0);
TMODULO(trem, tm->tm_sec, 1e0);
fsec = trem;
EncodeTimeOnly(tm, fsec, NULL, DateStyle, buf);
......@@ -466,6 +476,43 @@ time_out(PG_FUNCTION_ARGS)
PG_RETURN_CSTRING(result);
}
/* time_scale()
* Adjust time type for specified scale factor.
* Used by PostgreSQL type system to stuff columns.
*/
Datum
time_scale(PG_FUNCTION_ARGS)
{
TimeADT time = PG_GETARG_TIMEADT(0);
int32 typmod = PG_GETARG_INT32(1);
TimeADT result;
result = time;
AdjustTimeForTypmod(&result, typmod);
PG_RETURN_TIMEADT(result);
}
static void
AdjustTimeForTypmod(TimeADT *time, int32 typmod)
{
if ((typmod >= 0) && (typmod <= 13))
{
static double TimeScale = 1;
static int32 TimeTypmod = 0;
if (typmod != TimeTypmod)
TimeScale = pow(10, typmod);
*time = (rint(((double) *time)*TimeScale)/TimeScale);
if (*time >= 86400)
*time -= 86400;
}
return;
}
Datum
time_eq(PG_FUNCTION_ARGS)
......@@ -882,12 +929,15 @@ text_time(PG_FUNCTION_ARGS)
* Time With Time Zone ADT
*****************************************************************************/
Datum
timetz_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
TimeTzADT *time;
#ifdef NOT_USED
Oid typelem = PG_GETARG_OID(1);
#endif
int32 typmod = PG_GETARG_INT32(2);
TimeTzADT *result;
double fsec;
struct tm tt,
*tm = &tt;
......@@ -902,12 +952,14 @@ timetz_in(PG_FUNCTION_ARGS)
|| (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
elog(ERROR, "Bad time external representation '%s'", str);
time = (TimeTzADT *) palloc(sizeof(TimeTzADT));
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
result->time = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
result->zone = tz;
time->time = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
time->zone = tz;
AdjustTimeForTypmod(&(result->time), typmod);
PG_RETURN_TIMETZADT_P(time);
PG_RETURN_TIMETZADT_P(result);
}
Datum
......@@ -919,13 +971,15 @@ timetz_out(PG_FUNCTION_ARGS)
*tm = &tt;
double fsec;
int tz;
double trem;
char buf[MAXDATELEN + 1];
tm->tm_hour = (time->time / (60 * 60));
tm->tm_min = (((int) (time->time / 60)) % 60);
tm->tm_sec = (((int) time->time) % 60);
trem = time->time;
TMODULO(trem, tm->tm_hour, 3600e0);
TMODULO(trem, tm->tm_min, 60e0);
TMODULO(trem, tm->tm_sec, 1e0);
fsec = trem;
fsec = 0;
tz = time->zone;
EncodeTimeOnly(tm, fsec, &tz, DateStyle, buf);
......@@ -934,6 +988,27 @@ timetz_out(PG_FUNCTION_ARGS)
PG_RETURN_CSTRING(result);
}
/* timetz_scale()
* Adjust time type for specified scale factor.
* Used by PostgreSQL type system to stuff columns.
*/
Datum
timetz_scale(PG_FUNCTION_ARGS)
{
TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
int32 typmod = PG_GETARG_INT32(1);
TimeTzADT *result;
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
result->time = time->time;
result->zone = time->zone;
AdjustTimeForTypmod(&(result->time), typmod);
PG_RETURN_TIMETZADT_P(result);
}
static int
timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.67 2001/09/28 08:09:10 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.68 2001/10/03 05:29:24 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -26,8 +26,6 @@
#include "utils/datetime.h"
#define ROUND_ALL 1
static int DecodeNumber(int flen, char *field,
int fmask, int *tmask,
struct tm * tm, double *fsec, int *is2digits);
......@@ -2173,8 +2171,27 @@ EncodeTimeOnly(struct tm * tm, double fsec, int *tzp, int style, char *str)
sec = (tm->tm_sec + fsec);
sprintf(str, "%02d:%02d:", tm->tm_hour, tm->tm_min);
sprintf((str + 6), ((fsec != 0) ? "%05.2f" : "%02.0f"), sec);
sprintf(str, "%02d:%02d", tm->tm_hour, tm->tm_min);
/* If we have fractional seconds, then include a decimal point
* We will do up to 6 fractional digits, and we have rounded any inputs
* to eliminate anything to the right of 6 digits anyway.
* If there are no fractional seconds, then do not bother printing
* a decimal point at all. - thomas 2001-09-29
*/
if (fsec != 0) {
sprintf((str + strlen(str)), ":%013.10f", sec);
/* chop off trailing pairs of zeros... */
while ((strcmp((str + strlen(str) - 2), "00") == 0)
&& (*(str + strlen(str) - 3) != '.'))
{
*(str + strlen(str) - 2) = '\0';
}
}
else
{
sprintf((str + strlen(str)), ":%02.0f", sec);
}
if (tzp != NULL)
{
......@@ -2221,9 +2238,28 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
case USE_ISO_DATES:
if (tm->tm_year > 0)
{
sprintf(str, "%04d-%02d-%02d %02d:%02d:",
sprintf(str, "%04d-%02d-%02d %02d:%02d",
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min);
sprintf((str + strlen(str)), ((fsec != 0) ? "%05.2f" : "%02.0f"), sec);
/* If we have fractional seconds, then include a decimal point
* We will do up to 6 fractional digits, and we have rounded any inputs
* to eliminate anything to the right of 6 digits anyway.
* If there are no fractional seconds, then do not bother printing
* a decimal point at all. - thomas 2001-09-29
*/
if (fsec != 0) {
sprintf((str + strlen(str)), ":%013.10f", sec);
/* chop off trailing pairs of zeros... */
while ((strcmp((str + strlen(str) - 2), "00") == 0)
&& (*(str + strlen(str) - 3) != '.'))
{
*(str + strlen(str) - 2) = '\0';
}
}
else
{
sprintf((str + strlen(str)), ":%02.0f", sec);
}
if ((*tzn != NULL) && (tm->tm_isdst >= 0))
{
......@@ -2261,8 +2297,28 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
if (tm->tm_year > 0)
{
sprintf((str + 5), "/%04d %02d:%02d:%05.2f",
tm->tm_year, tm->tm_hour, tm->tm_min, sec);
sprintf((str + 5), "/%04d %02d:%02d",
tm->tm_year, tm->tm_hour, tm->tm_min);
/* If we have fractional seconds, then include a decimal point
* We will do up to 6 fractional digits, and we have rounded any inputs
* to eliminate anything to the right of 6 digits anyway.
* If there are no fractional seconds, then do not bother printing
* a decimal point at all. - thomas 2001-09-29
*/
if (fsec != 0) {
sprintf((str + strlen(str)), ":%013.10f", sec);
/* chop off trailing pairs of zeros... */
while ((strcmp((str + strlen(str) - 2), "00") == 0)
&& (*(str + strlen(str) - 3) != '.'))
{
*(str + strlen(str) - 2) = '\0';
}
}
else
{
sprintf((str + strlen(str)), ":%02.0f", sec);
}
if ((*tzn != NULL) && (tm->tm_isdst >= 0))
sprintf((str + strlen(str)), " %.*s", MAXTZLEN, *tzn);
......@@ -2277,8 +2333,28 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
sprintf(str, "%02d.%02d", tm->tm_mday, tm->tm_mon);
if (tm->tm_year > 0)
{
sprintf((str + 5), ".%04d %02d:%02d:%05.2f",
tm->tm_year, tm->tm_hour, tm->tm_min, sec);
sprintf((str + 5), ".%04d %02d:%02d",
tm->tm_year, tm->tm_hour, tm->tm_min);
/* If we have fractional seconds, then include a decimal point
* We will do up to 6 fractional digits, and we have rounded any inputs
* to eliminate anything to the right of 6 digits anyway.
* If there are no fractional seconds, then do not bother printing
* a decimal point at all. - thomas 2001-09-29
*/
if (fsec != 0) {
sprintf((str + strlen(str)), ":%013.10f", sec);
/* chop off trailing pairs of zeros... */
while ((strcmp((str + strlen(str) - 2), "00") == 0)
&& (*(str + strlen(str) - 3) != '.'))
{
*(str + strlen(str) - 2) = '\0';
}
}
else
{
sprintf((str + strlen(str)), ":%02.0f", sec);
}
if ((*tzn != NULL) && (tm->tm_isdst >= 0))
sprintf((str + strlen(str)), " %.*s", MAXTZLEN, *tzn);
......@@ -2305,19 +2381,31 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
if (tm->tm_year > 0)
{
sprintf((str + 10), " %02d:%02d", tm->tm_hour, tm->tm_min);
if (fsec != 0)
/* If we have fractional seconds, then include a decimal point
* We will do up to 6 fractional digits, and we have rounded any inputs
* to eliminate anything to the right of 6 digits anyway.
* If there are no fractional seconds, then do not bother printing
* a decimal point at all. - thomas 2001-09-29
*/
if (fsec != 0) {
sprintf((str + strlen(str)), ":%013.10f", sec);
/* chop off trailing pairs of zeros... */
while ((strcmp((str + strlen(str) - 2), "00") == 0)
&& (*(str + strlen(str) - 3) != '.'))
{
sprintf((str + 16), ":%05.2f %04d", sec, tm->tm_year);
if ((*tzn != NULL) && (tm->tm_isdst >= 0))
sprintf((str + strlen(str)), " %.*s", MAXTZLEN, *tzn);
*(str + strlen(str) - 2) = '\0';
}
}
else
{
sprintf((str + 16), ":%02.0f %04d", sec, tm->tm_year);
sprintf((str + strlen(str)), ":%02.0f", sec);
}
sprintf((str + strlen(str)), " %04d", tm->tm_year);
if ((*tzn != NULL) && (tm->tm_isdst >= 0))
sprintf((str + strlen(str)), " %.*s", MAXTZLEN, *tzn);
}
}
else
{
sprintf((str + 10), " %02d:%02d %04d %s",
......
......@@ -5,7 +5,7 @@
*
* 1998 Jan Wieck
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.43 2001/08/14 22:21:58 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.44 2001/10/03 05:29:24 thomas Exp $
*
* ----------
*/
......@@ -193,10 +193,8 @@ Datum
numeric_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
#ifdef NOT_USED
Oid typelem = PG_GETARG_OID(1);
#endif
int32 typmod = PG_GETARG_INT32(2);
NumericVar value;
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.51 2001/09/28 08:09:11 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.52 2001/10/03 05:29:24 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -32,6 +32,8 @@
static double time2t(const int hour, const int min, const double sec);
static int EncodeSpecialTimestamp(Timestamp dt, char *str);
static Timestamp dt2local(Timestamp dt, int timezone);
static void
AdjustTimestampForTypmod(Timestamp *time, int32 typmod);
/*****************************************************************************
......@@ -45,6 +47,10 @@ Datum
timestamp_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
#ifdef NOT_USED
Oid typelem = PG_GETARG_OID(1);
#endif
int32 typmod = PG_GETARG_INT32(2);
Timestamp result;
double fsec;
struct tm tt,
......@@ -89,6 +95,8 @@ timestamp_in(PG_FUNCTION_ARGS)
TIMESTAMP_NOEND(result);
}
AdjustTimestampForTypmod(&result, typmod);
PG_RETURN_TIMESTAMP(result);
}
......@@ -98,7 +106,7 @@ timestamp_in(PG_FUNCTION_ARGS)
Datum
timestamp_out(PG_FUNCTION_ARGS)
{
Timestamp dt = PG_GETARG_TIMESTAMP(0);
Timestamp timestamp = PG_GETARG_TIMESTAMP(0);
char *result;
struct tm tt,
*tm = &tt;
......@@ -106,9 +114,9 @@ timestamp_out(PG_FUNCTION_ARGS)
char *tzn = NULL;
char buf[MAXDATELEN + 1];
if (TIMESTAMP_NOT_FINITE(dt))
EncodeSpecialTimestamp(dt, buf);
else if (timestamp2tm(dt, NULL, tm, &fsec, NULL) == 0)
if (TIMESTAMP_NOT_FINITE(timestamp))
EncodeSpecialTimestamp(timestamp, buf);
else if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) == 0)
EncodeDateTime(tm, fsec, NULL, &tzn, DateStyle, buf);
else
elog(ERROR, "Unable to format timestamp; internal coding error");
......@@ -117,6 +125,42 @@ timestamp_out(PG_FUNCTION_ARGS)
PG_RETURN_CSTRING(result);
}
/* timestamp_scale()
* Adjust time type for specified scale factor.
* Used by PostgreSQL type system to stuff columns.
*/
Datum
timestamp_scale(PG_FUNCTION_ARGS)
{
Timestamp timestamp = PG_GETARG_TIMESTAMP(0);
int32 typmod = PG_GETARG_INT32(1);
Timestamp result;
result = timestamp;
if (! TIMESTAMP_NOT_FINITE(result))
AdjustTimestampForTypmod(&result, typmod);
PG_RETURN_TIMESTAMP(result);
}
static void
AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
{
if ((typmod >= 0) && (typmod <= 13))
{
static double TimestampScale = 1;
static int32 TimestampTypmod = 0;
if (typmod != TimestampTypmod)
TimestampScale = pow(10, typmod);
*time = (rint(((double) *time)*TimestampScale)/TimestampScale);
}
return;
}
/* timestamptz_in()
* Convert a string to internal form.
......@@ -125,6 +169,10 @@ Datum
timestamptz_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
#ifdef NOT_USED
Oid typelem = PG_GETARG_OID(1);
#endif
int32 typmod = PG_GETARG_INT32(2);
TimestampTz result;
double fsec;
struct tm tt,
......@@ -169,6 +217,8 @@ timestamptz_in(PG_FUNCTION_ARGS)
TIMESTAMP_NOEND(result);
}
AdjustTimestampForTypmod(&result, typmod);
PG_RETURN_TIMESTAMPTZ(result);
}
......@@ -198,6 +248,25 @@ timestamptz_out(PG_FUNCTION_ARGS)
PG_RETURN_CSTRING(result);
}
/* timestamptz_scale()
* Adjust time type for specified scale factor.
* Used by PostgreSQL type system to stuff columns.
*/
Datum
timestamptz_scale(PG_FUNCTION_ARGS)
{
TimestampTz timestamp = PG_GETARG_TIMESTAMP(0);
int32 typmod = PG_GETARG_INT32(1);
TimestampTz result;
result = timestamp;
if (! TIMESTAMP_NOT_FINITE(result))
AdjustTimestampForTypmod(&result, typmod);
PG_RETURN_TIMESTAMPTZ(result);
}
/* interval_in()
* Convert a string to internal form.
......@@ -2119,16 +2188,13 @@ timestamp_part(PG_FUNCTION_ARGS)
text *units = PG_GETARG_TEXT_P(0);
Timestamp timestamp = PG_GETARG_TIMESTAMP(1);
float8 result;
int tz;
int type,
val;
int i;
char *up,
*lp,
lowunits[MAXDATELEN + 1];
double dummy;
double fsec;
char *tzn;
struct tm tt,
*tm = &tt;
......@@ -2152,24 +2218,10 @@ timestamp_part(PG_FUNCTION_ARGS)
PG_RETURN_FLOAT8(result);
}
if ((type == UNITS) && (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) == 0))
if ((type == UNITS) && (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) == 0))
{
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 = (fsec * 1000000);
break;
......@@ -2222,11 +2274,13 @@ timestamp_part(PG_FUNCTION_ARGS)
result = (tm->tm_year / 1000);
break;
case DTK_TZ:
case DTK_TZ_MINUTE:
case DTK_TZ_HOUR:
default:
elog(ERROR, "Timestamp units '%s' not supported", lowunits);
result = 0;
}
}
else if (type == RESERV)
{
......@@ -2237,14 +2291,14 @@ timestamp_part(PG_FUNCTION_ARGS)
break;
case DTK_DOW:
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0)
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
elog(ERROR, "Unable to encode timestamp");
result = j2day(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday));
break;
case DTK_DOY:
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0)
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
elog(ERROR, "Unable to encode timestamp");
result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.82 2001/09/11 05:18:59 ishii Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.83 2001/10/03 05:29:24 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -33,7 +33,7 @@
* at CREATE TABLE time.
*
* It's hard to implement these types because we cannot figure out
* the length of the type from the type itself. I change (hopefully all) the
* the length of the type from the type itself. I changed (hopefully all) the
* fmgr calls that invoke input functions of a data type to supply the
* length also. (eg. in INSERTs, we have the tupleDescriptor which contains
* the length of the attributes and hence the exact length of the char() or
......
......@@ -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.96 2001/09/28 08:09:13 thomas Exp $
* $Id: catversion.h,v 1.97 2001/10/03 05:29:24 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
#define CATALOG_VERSION_NO 200109261
#define CATALOG_VERSION_NO 200110011
#endif
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: date.h,v 1.12 2001/09/28 08:09:14 thomas Exp $
* $Id: date.h,v 1.13 2001/10/03 05:29:25 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -77,6 +77,7 @@ extern Datum date_text(PG_FUNCTION_ARGS);
extern Datum time_in(PG_FUNCTION_ARGS);
extern Datum time_out(PG_FUNCTION_ARGS);
extern Datum time_scale(PG_FUNCTION_ARGS);
extern Datum time_eq(PG_FUNCTION_ARGS);
extern Datum time_ne(PG_FUNCTION_ARGS);
extern Datum time_lt(PG_FUNCTION_ARGS);
......@@ -99,6 +100,7 @@ extern Datum interval_pl_time(PG_FUNCTION_ARGS);
extern Datum timetz_in(PG_FUNCTION_ARGS);
extern Datum timetz_out(PG_FUNCTION_ARGS);
extern Datum timetz_scale(PG_FUNCTION_ARGS);
extern Datum timetz_eq(PG_FUNCTION_ARGS);
extern Datum timetz_ne(PG_FUNCTION_ARGS);
extern Datum timetz_lt(PG_FUNCTION_ARGS);
......
......@@ -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.18 2001/09/28 08:09:14 thomas Exp $
* $Id: timestamp.h,v 1.19 2001/10/03 05:29:25 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -91,6 +91,7 @@ typedef struct
extern Datum timestamp_in(PG_FUNCTION_ARGS);
extern Datum timestamp_out(PG_FUNCTION_ARGS);
extern Datum timestamp_scale(PG_FUNCTION_ARGS);
extern Datum timestamp_eq(PG_FUNCTION_ARGS);
extern Datum timestamp_ne(PG_FUNCTION_ARGS);
extern Datum timestamp_lt(PG_FUNCTION_ARGS);
......@@ -130,6 +131,7 @@ extern Datum timestamp_timestamptz(PG_FUNCTION_ARGS);
extern Datum timestamptz_in(PG_FUNCTION_ARGS);
extern Datum timestamptz_out(PG_FUNCTION_ARGS);
extern Datum timestamptz_scale(PG_FUNCTION_ARGS);
extern Datum timestamptz_timestamp(PG_FUNCTION_ARGS);
extern Datum timestamptz_zone(PG_FUNCTION_ARGS);
extern Datum timestamptz_izone(PG_FUNCTION_ARGS);
......
This diff is collapsed.
--
-- TIME
--
CREATE TABLE TIME_TBL (f1 time);
CREATE TABLE TIME_TBL (f1 time(2));
INSERT INTO TIME_TBL VALUES ('00:00');
INSERT INTO TIME_TBL VALUES ('01:00');
INSERT INTO TIME_TBL VALUES ('02:03');
......@@ -16,7 +16,7 @@ INSERT INTO TIME_TBL VALUES ('23:59');
INSERT INTO TIME_TBL VALUES ('11:59:59.99 PM');
SELECT f1 AS "Time" FROM TIME_TBL;
Time
----------
-------------
00:00:00
01:00:00
02:03:00
......@@ -24,7 +24,7 @@ SELECT f1 AS "Time" FROM TIME_TBL;
12:00:00
12:01:00
23:59:00
23:59:59
23:59:59.99
(8 rows)
SELECT f1 AS "Three" FROM TIME_TBL WHERE f1 < '05:06:07';
......@@ -37,12 +37,12 @@ SELECT f1 AS "Three" FROM TIME_TBL WHERE f1 < '05:06:07';
SELECT f1 AS "Five" FROM TIME_TBL WHERE f1 > '05:06:07';
Five
----------
-------------
11:59:00
12:00:00
12:01:00
23:59:00
23:59:59
23:59:59.99
(5 rows)
SELECT f1 AS "None" FROM TIME_TBL WHERE f1 < '00:00';
......@@ -52,7 +52,7 @@ SELECT f1 AS "None" FROM TIME_TBL WHERE f1 < '00:00';
SELECT f1 AS "Eight" FROM TIME_TBL WHERE f1 >= '00:00';
Eight
----------
-------------
00:00:00
01:00:00
02:03:00
......@@ -60,7 +60,7 @@ SELECT f1 AS "Eight" FROM TIME_TBL WHERE f1 >= '00:00';
12:00:00
12:01:00
23:59:00
23:59:59
23:59:59.99
(8 rows)
--
......
This diff is collapsed.
This diff is collapsed.
--
-- TIMETZ
--
CREATE TABLE TIMETZ_TBL (f1 time with time zone);
CREATE TABLE TIMETZ_TBL (f1 time(2) with time zone);
INSERT INTO TIMETZ_TBL VALUES ('00:01 PDT');
INSERT INTO TIMETZ_TBL VALUES ('01:00 PDT');
INSERT INTO TIMETZ_TBL VALUES ('02:03 PDT');
......@@ -14,7 +14,7 @@ INSERT INTO TIMETZ_TBL VALUES ('23:59 PDT');
INSERT INTO TIMETZ_TBL VALUES ('11:59:59.99 PM PDT');
SELECT f1 AS "Time TZ" FROM TIMETZ_TBL;
Time TZ
-------------
----------------
00:01:00-07
01:00:00-07
02:03:00-07
......@@ -24,7 +24,7 @@ SELECT f1 AS "Time TZ" FROM TIMETZ_TBL;
12:00:00-07
12:01:00-07
23:59:00-07
23:59:59-07
23:59:59.99-07
(10 rows)
SELECT f1 AS "Three" FROM TIMETZ_TBL WHERE f1 < '05:06:07';
......@@ -37,14 +37,14 @@ SELECT f1 AS "Three" FROM TIMETZ_TBL WHERE f1 < '05:06:07';
SELECT f1 AS "Seven" FROM TIMETZ_TBL WHERE f1 > '05:06:07';
Seven
-------------
----------------
07:07:00-08
08:08:00-04
11:59:00-07
12:00:00-07
12:01:00-07
23:59:00-07
23:59:59-07
23:59:59.99-07
(7 rows)
SELECT f1 AS "None" FROM TIMETZ_TBL WHERE f1 < '00:00';
......@@ -54,7 +54,7 @@ SELECT f1 AS "None" FROM TIMETZ_TBL WHERE f1 < '00:00';
SELECT f1 AS "Ten" FROM TIMETZ_TBL WHERE f1 >= '00:00';
Ten
-------------
----------------
00:01:00-07
01:00:00-07
02:03:00-07
......@@ -64,7 +64,7 @@ SELECT f1 AS "Ten" FROM TIMETZ_TBL WHERE f1 >= '00:00';
12:00:00-07
12:01:00-07
23:59:00-07
23:59:59-07
23:59:59.99-07
(10 rows)
--
......
......@@ -35,10 +35,13 @@ SELECT (timestamp without time zone 'today' = (timestamp without time zone 'tomo
SELECT (timestamp without time zone 'tomorrow' = (timestamp without time zone 'yesterday' + interval '2 days')) as "True";
SELECT (timestamp without time zone 'tomorrow' > 'now') as "True";
SELECT timestamp(date '1994-01-01', time '11:00') AS "Jan_01_1994_11am";
SELECT timestamp(date '1994-01-01', time '10:00') AS "Jan_01_1994_10am";
SELECT timestamp(date '1994-01-01', time '11:00-5') AS "Jan_01_1994_8am";
SELECT timestamp(date '1994-01-01', time with time zone '11:00-5') AS "Jan_01_1994_11am";
-- Convert from date and time to timestamp
-- This test used to be timestamp(date,time) but no longer allowed by grammar
-- to enable support for SQL99 timestamp type syntax.
SELECT date '1994-01-01' + time '11:00' AS "Jan_01_1994_11am";
SELECT date '1994-01-01' + time '10:00' AS "Jan_01_1994_10am";
SELECT date '1994-01-01' + time '11:00-5' AS "Jan_01_1994_8am";
SELECT "timestamp"(date '1994-01-01', time with time zone '11:00-5') AS "Jan_01_1994_11am";
SELECT '' AS "64", d1 + interval '1 year' AS one_year FROM TIMESTAMP_TBL;
SELECT '' AS "64", d1 - interval '1 year' AS one_year FROM TIMESTAMP_TBL;
......@@ -170,20 +173,20 @@ INSERT INTO TEMP_TIMESTAMP (f1)
WHERE d1 BETWEEN '13-jun-1957' AND '1-jan-1997'
OR d1 BETWEEN '1-jan-1999' AND '1-jan-2010';
SELECT '' AS "16", f1 AS timestamp
SELECT '' AS "16", f1 AS "timestamp"
FROM TEMP_TIMESTAMP
ORDER BY 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,
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
FROM TEMP_TIMESTAMP d
ORDER BY difference;
......@@ -192,14 +195,6 @@ SELECT '' AS "226", d1.f1 AS timestamp1, d2.f1 AS timestamp2, d1.f1 - d2.f1 AS d
FROM TEMP_TIMESTAMP d1, TEMP_TIMESTAMP d2
ORDER BY timestamp1, timestamp2, difference;
SELECT '' as "55", d1 as timestamp,
date_part('year', d1) AS year, date_part('month', d1) AS month,
date_part('day',d1) AS day, date_part('hour', d1) AS hour,
date_part('minute', d1) AS minute, date_part('second', d1) AS second
FROM TIMESTAMP_TBL
WHERE isfinite(d1) and d1 >= '1-jan-1900 GMT'
ORDER BY timestamp;
--
-- abstime, reltime arithmetic
--
......@@ -232,12 +227,12 @@ SELECT '' AS three, ABSTIME_TBL.*
-- Conversions
--
SELECT '' AS "16", f1 AS timestamp, date(f1) AS date
SELECT '' AS "16", f1 AS "timestamp", date(f1) AS date
FROM TEMP_TIMESTAMP
WHERE f1 <> timestamp 'current'
ORDER BY date, timestamp;
ORDER BY date, "timestamp";
SELECT '' AS "16", f1 AS timestamp, abstime(f1) AS abstime
SELECT '' AS "16", f1 AS "timestamp", abstime(f1) AS abstime
FROM TEMP_TIMESTAMP
ORDER BY abstime;
......@@ -246,10 +241,10 @@ SELECT '' AS four, f1 AS abstime, date(f1) AS date
WHERE isfinite(f1) AND f1 <> abstime 'current'
ORDER BY date, abstime;
SELECT '' AS two, d1 AS timestamp, abstime(d1) AS abstime
SELECT '' AS two, d1 AS "timestamp", abstime(d1) AS abstime
FROM TIMESTAMP_TBL WHERE NOT isfinite(d1);
SELECT '' AS three, f1 as abstime, timestamp(f1) AS timestamp
SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp"
FROM ABSTIME_TBL WHERE NOT isfinite(f1);
SELECT '' AS ten, f1 AS interval, reltime(f1) AS reltime
......
......@@ -2,7 +2,7 @@
-- TIME
--
CREATE TABLE TIME_TBL (f1 time);
CREATE TABLE TIME_TBL (f1 time(2));
INSERT INTO TIME_TBL VALUES ('00:00');
INSERT INTO TIME_TBL VALUES ('01:00');
......
......@@ -4,7 +4,7 @@
-- needed so tests pass even in Australia
SET australian_timezones = 'off';
CREATE TABLE TIMESTAMP_TBL ( d1 timestamp without time zone);
CREATE TABLE TIMESTAMP_TBL ( d1 timestamp(2) without time zone);
-- Shorthand values
-- Not directly usable for regression testing since these are not constants.
......@@ -153,12 +153,14 @@ SELECT '' AS "54", d1 - timestamp without time zone '1997-01-02' AS diff
WHERE d1 BETWEEN timestamp without time zone '1902-01-01'
AND timestamp without time zone '2038-01-01';
SELECT '' AS "54", date_part( 'year', d1) AS year, date_part( 'month', d1) AS month,
SELECT '' AS "54", d1 as "timestamp",
date_part( 'year', d1) AS year, date_part( 'month', d1) AS month,
date_part( 'day', d1) AS day, date_part( 'hour', d1) AS hour,
date_part( 'minute', d1) AS minute, date_part( 'second', d1) AS second
FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
SELECT '' AS "54", date_part( 'quarter', d1) AS quarter, date_part( 'msec', d1) AS msec,
SELECT '' AS "54", d1 as "timestamp",
date_part( 'quarter', d1) AS quarter, date_part( 'msec', d1) AS msec,
date_part( 'usec', d1) AS usec
FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
......
......@@ -4,7 +4,7 @@
-- needed so tests pass even in Australia
SET australian_timezones = 'off';
CREATE TABLE TIMESTAMPTZ_TBL ( d1 timestamp with time zone);
CREATE TABLE TIMESTAMPTZ_TBL ( d1 timestamp(2) with time zone);
INSERT INTO TIMESTAMPTZ_TBL VALUES ('now');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('current');
......@@ -148,12 +148,14 @@ SELECT '' AS "54", d1 - timestamp with time zone '1997-01-02' AS diff
FROM TIMESTAMPTZ_TBL
WHERE d1 BETWEEN timestamp with time zone '1902-01-01' AND timestamp with time zone '2038-01-01';
SELECT '' AS "54", date_part( 'year', d1) AS year, date_part( 'month', d1) AS month,
SELECT '' AS "54", d1 as timestamptz,
date_part( 'year', d1) AS year, date_part( 'month', d1) AS month,
date_part( 'day', d1) AS day, date_part( 'hour', d1) AS hour,
date_part( 'minute', d1) AS minute, date_part( 'second', d1) AS second
FROM TIMESTAMPTZ_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
SELECT '' AS "54", date_part( 'quarter', d1) AS quarter, date_part( 'msec', d1) AS msec,
SELECT '' AS "54", d1 as timestamptz,
date_part( 'quarter', d1) AS quarter, date_part( 'msec', d1) AS msec,
date_part( 'usec', d1) AS usec
FROM TIMESTAMPTZ_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
......
......@@ -2,7 +2,7 @@
-- TIMETZ
--
CREATE TABLE TIMETZ_TBL (f1 time with time zone);
CREATE TABLE TIMETZ_TBL (f1 time(2) with time zone);
INSERT INTO TIMETZ_TBL VALUES ('00:01 PDT');
INSERT INTO TIMETZ_TBL VALUES ('01:00 PDT');
......
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