提交 d6bdd0eb authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Restore support of DATETIME(precision)

上级 0b9b6cf0
......@@ -2671,11 +2671,12 @@ DATE
"Data Types","TIMESTAMP Type","
{ TIMESTAMP [ ( precisionInt ) ] [ WITHOUT TIME ZONE ]
| DATETIME | SMALLDATETIME }
| DATETIME [ ( precisionInt ) ] | SMALLDATETIME }
","
The timestamp data type. The format is yyyy-MM-dd hh:mm:ss[.nnnnnnnnn].
Stored internally as a BCD-encoded date, and nanoseconds since midnight.
If fractional seconds precision is specified it should be from 0 to 9, 6 is default.
Fractional seconds precision of SMALLDATETIME is always 0 and cannot be specified.
Mapped to ""java.sql.Timestamp"" (""java.util.Date"" may be used too).
""java.time.LocalDateTime"" is also supported on Java 8 and later versions.
......
......@@ -4475,6 +4475,20 @@ public class Parser {
precision = displaySize = ValueTimestampTimeZone.getDisplaySize(originalScale);
break;
}
} else if (original.equals("DATETIME")) {
if (readIf("(")) {
originalScale = readPositiveInt();
if (originalScale > ValueTime.MAXIMUM_SCALE) {
throw DbException.get(ErrorCode.INVALID_VALUE_SCALE_PRECISION, Integer.toString(originalScale));
}
read(")");
scale = originalScale;
original = original + '(' + originalScale + ')';
precision = displaySize = ValueTimestamp.getDisplaySize(originalScale);
}
} else if (original.equals("SMALLDATETIME")) {
scale = 0;
precision = displaySize = ValueTimestamp.getDisplaySize(0);
}
} else if (readIf("(")) {
if (!readIf("MAX")) {
......@@ -4562,7 +4576,6 @@ public class Parser {
Integer.toString(scale), Long.toString(precision));
}
Column column = new Column(columnName, type, precision, scale,
displaySize, enumerators);
if (templateColumn != null) {
......
......@@ -15,7 +15,9 @@ SELECT T1, T2, T1 = T2 FROM TEST;
> 2010-01-01 10:00:00 2010-01-01 10:00:00 TRUE
> rows: 1
ALTER TABLE TEST ADD (T3 TIMESTAMP(0), T4 TIMESTAMP(9) WITHOUT TIME ZONE);
ALTER TABLE TEST ADD (T3 TIMESTAMP(0), T4 TIMESTAMP(9) WITHOUT TIME ZONE,
DT1 DATETIME, DT2 DATETIME(0), DT3 DATETIME(9), SDT1 SMALLDATETIME);
> ok
SELECT COLUMN_NAME, DATA_TYPE, TYPE_NAME, COLUMN_TYPE, NUMERIC_SCALE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'TEST' ORDER BY ORDINAL_POSITION;
......@@ -25,11 +27,21 @@ SELECT COLUMN_NAME, DATA_TYPE, TYPE_NAME, COLUMN_TYPE, NUMERIC_SCALE FROM INFORM
> T2 93 TIMESTAMP TIMESTAMP WITHOUT TIME ZONE 6
> T3 93 TIMESTAMP TIMESTAMP(0) 0
> T4 93 TIMESTAMP TIMESTAMP(9) WITHOUT TIME ZONE 9
> rows (ordered): 4
> DT1 93 TIMESTAMP DATETIME 6
> DT2 93 TIMESTAMP DATETIME(0) 0
> DT3 93 TIMESTAMP DATETIME(9) 9
> SDT1 93 TIMESTAMP SMALLDATETIME 0
> rows (ordered): 8
ALTER TABLE TEST ADD T5 TIMESTAMP(10);
> exception
ALTER TABLE TEST ADD DT4 DATETIME(10);
> exception
ALTER TABLE TEST ADD STD2 SMALLDATETIME(1);
> exception
DROP TABLE TEST;
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论