Commit eda51264 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Allow variable (unrestricted) precision for TIME and TIMESTAMP types in parser.

parent cd8b3549
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.275 2001/11/16 04:08:33 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.276 2001/12/09 04:39:39 thomas Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -888,16 +888,26 @@ zone_value: Sconst ...@@ -888,16 +888,26 @@ zone_value: Sconst
{ {
A_Const *n = (A_Const *) makeStringConst($2, $1); A_Const *n = (A_Const *) makeStringConst($2, $1);
if ($3 != -1) if ($3 != -1)
n->typename->typmod = (($3 << 16) | 0xFFFF); {
if (($3 & ~(MASK(HOUR) | MASK(MINUTE))) != 0)
elog(ERROR, "Time zone interval must be HOUR or HOUR TO MINUTE");
n->typename->typmod = ((($3 & 0x7FFF) << 16) | 0xFFFF);
}
$$ = (Node *)n; $$ = (Node *)n;
} }
| ConstInterval '(' Iconst ')' Sconst opt_interval | ConstInterval '(' Iconst ')' Sconst opt_interval
{ {
A_Const *n = (A_Const *) makeStringConst($5, $1); A_Const *n = (A_Const *) makeStringConst($5, $1);
if ($6 != -1) if ($6 != -1)
n->typename->typmod = (($6 << 16) | $3); {
if (($6 & ~(MASK(HOUR) | MASK(MINUTE))) != 0)
elog(ERROR, "Time zone interval must be HOUR or HOUR TO MINUTE");
n->typename->typmod = ((($6 & 0x7FFF) << 16) | $3);
}
else else
{
n->typename->typmod = ((0x7FFF << 16) | $3); n->typename->typmod = ((0x7FFF << 16) | $3);
}
$$ = (Node *)n; $$ = (Node *)n;
} }
...@@ -4328,10 +4338,14 @@ ConstDatetime: TIMESTAMP '(' Iconst ')' opt_timezone_x ...@@ -4328,10 +4338,14 @@ ConstDatetime: TIMESTAMP '(' Iconst ')' opt_timezone_x
* - thomas 2001-09-06 * - thomas 2001-09-06
*/ */
$$->timezone = $2; $$->timezone = $2;
/* SQL99 specified a default precision of six. /* SQL99 specified a default precision of six
* - thomas 2001-09-30 * for schema definitions. But for timestamp
* literals we don't want to throw away precision
* so leave this as unspecified for now.
* Later, we may want a different production
* for schemas. - thomas 2001-12-07
*/ */
$$->typmod = 6; $$->typmod = -1;
} }
| TIME '(' Iconst ')' opt_timezone | TIME '(' Iconst ')' opt_timezone
{ {
...@@ -4353,9 +4367,10 @@ ConstDatetime: TIMESTAMP '(' Iconst ')' opt_timezone_x ...@@ -4353,9 +4367,10 @@ ConstDatetime: TIMESTAMP '(' Iconst ')' opt_timezone_x
else else
$$->name = xlateSqlType("time"); $$->name = xlateSqlType("time");
/* SQL99 specified a default precision of zero. /* SQL99 specified a default precision of zero.
* - thomas 2001-09-30 * See comments for timestamp above on why we will
* leave this unspecified for now. - thomas 2001-12-07
*/ */
$$->typmod = 0; $$->typmod = -1;
} }
; ;
...@@ -5009,7 +5024,12 @@ c_expr: attr ...@@ -5009,7 +5024,12 @@ c_expr: attr
d->name = xlateSqlType("timetz"); d->name = xlateSqlType("timetz");
d->setof = FALSE; d->setof = FALSE;
d->typmod = 0; /* SQL99 mandates a default precision of zero for TIME
* fields in schemas. However, for CURRENT_TIME
* let's preserve the microsecond precision we
* might see from the system clock. - thomas 2001-12-07
*/
d->typmod = 6;
$$ = (Node *)makeTypeCast((Node *)s, d); $$ = (Node *)makeTypeCast((Node *)s, d);
} }
...@@ -5058,11 +5078,13 @@ c_expr: attr ...@@ -5058,11 +5078,13 @@ c_expr: attr
t->setof = FALSE; t->setof = FALSE;
t->typmod = -1; t->typmod = -1;
/* SQL99 mandates a default precision of 6
* for timestamp. - thomas 2001-10-04
*/
d->name = xlateSqlType("timestamptz"); d->name = xlateSqlType("timestamptz");
d->setof = FALSE; d->setof = FALSE;
/* SQL99 mandates a default precision of 6 for timestamp.
* Also, that is about as precise as we will get since
* we are using a microsecond time interface.
* - thomas 2001-12-07
*/
d->typmod = 6; d->typmod = 6;
$$ = (Node *)makeTypeCast((Node *)s, d); $$ = (Node *)makeTypeCast((Node *)s, d);
......
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