提交 70f77ae5 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Parse TIME WITHOUT TIME ZONE as TIME

上级 27f2c8d6
......@@ -2298,7 +2298,7 @@ Each table has a pseudo-column named ""_ROWID_"" that contains the unique row id
"
"Other Grammar","Time","
TIME 'hh:mm:ss[.nnnnnnnnn]'
TIME [ WITHOUT TIME ZONE ] 'hh:mm:ss[.nnnnnnnnn]'
","
A time literal. A value is between 0:00:00 and 23:59:59.999999999
and has nanosecond resolution.
......@@ -2433,7 +2433,7 @@ REAL
"
"Data Types","TIME Type","
TIME
TIME [ WITHOUT TIME ZONE ]
","
The time data type. The format is hh:mm:ss[.nnnnnnnnn].
......
......@@ -3137,6 +3137,23 @@ public class Parser {
read("FOR");
Sequence sequence = readSequence();
r = new SequenceValue(sequence);
} else if (equalsToken("TIME", name)) {
boolean without = readIf("WITHOUT");
if (without) {
read("TIME");
read("ZONE");
}
if (currentTokenType != VALUE
|| currentValue.getType() != Value.STRING) {
if (without) {
throw getSyntaxError();
}
r = new ExpressionColumn(database, null, null, name);
} else {
String time = currentValue.getString();
read();
r = ValueExpression.get(ValueTime.parse(time));
}
} else if (equalsToken("TIMESTAMP", name)) {
if (readIf("WITH")) {
read("TIME");
......@@ -4345,6 +4362,12 @@ public class Parser {
if (readIf("VARYING")) {
original += " VARYING";
}
} else if (readIf("TIME")) {
if (readIf("WITHOUT")) {
read("TIME");
read("ZONE");
original += " WITHOUT TIME ZONE";
}
} else if (readIf("TIMESTAMP")) {
if (readIf("WITH")) {
read("TIME");
......
......@@ -289,7 +289,7 @@ public class DataType {
);
add(Value.TIME, Types.TIME, "Time",
createDate(ValueTime.PRECISION, "TIME", 0, ValueTime.DISPLAY_SIZE),
new String[]{"TIME"},
new String[]{"TIME", "TIME WITHOUT TIME ZONE"},
// 24 for ValueTime, 32 for java.sql.Time
56
);
......
......@@ -2,3 +2,42 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
CREATE TABLE TEST(T1 TIME, T2 TIME WITHOUT TIME ZONE);
> ok
INSERT INTO TEST(T1, T2) VALUES (TIME '10:00:00', TIME WITHOUT TIME ZONE '10:00:00');
> update count: 1
SELECT T1, T2, T1 = T2 FROM TEST;
> T1 T2 T1 = T2
> -------- -------- -------
> 10:00:00 10:00:00 TRUE
> rows: 1
SELECT COLUMN_NAME, DATA_TYPE, TYPE_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'TEST' ORDER BY ORDINAL_POSITION;
> COLUMN_NAME DATA_TYPE TYPE_NAME COLUMN_TYPE
> ----------- --------- --------- ----------------------
> T1 92 TIME TIME
> T2 92 TIME TIME WITHOUT TIME ZONE
> rows (ordered): 2
DROP TABLE TEST;
> ok
-- Check that TIME is allowed as a column name
CREATE TABLE TEST(TIME TIME);
> ok
INSERT INTO TEST VALUES (TIME '08:00:00');
> update count: 1
SELECT TIME FROM TEST;
> TIME
> --------
> 08:00:00
> rows: 1
DROP TABLE TEST;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论