提交 873aac59 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Parse TIMESTAMP WITHOUT TIME ZONE as TIMESTAMP

上级 b9927766
...@@ -2309,7 +2309,7 @@ TIME '23:59:59' ...@@ -2309,7 +2309,7 @@ TIME '23:59:59'
" "
"Other Grammar","Timestamp"," "Other Grammar","Timestamp","
TIMESTAMP 'yyyy-MM-dd hh:mm:ss[.nnnnnnnnn]' TIMESTAMP [ WITHOUT TIME ZONE ] 'yyyy-MM-dd hh:mm:ss[.nnnnnnnnn]'
"," ","
A timestamp literal. The limitations are the same as for the Java data type A timestamp literal. The limitations are the same as for the Java data type
""java.sql.Timestamp"", but for compatibility with other databases the suggested ""java.sql.Timestamp"", but for compatibility with other databases the suggested
...@@ -2459,7 +2459,7 @@ DATE ...@@ -2459,7 +2459,7 @@ DATE
" "
"Data Types","TIMESTAMP Type"," "Data Types","TIMESTAMP Type","
{ TIMESTAMP | DATETIME | SMALLDATETIME } { TIMESTAMP [ WITHOUT TIME ZONE ] | DATETIME | SMALLDATETIME }
"," ","
The timestamp data type. The format is yyyy-MM-dd hh:mm:ss[.nnnnnnnnn]. 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. Stored internally as a BCD-encoded date, and nanoseconds since midnight.
......
...@@ -3137,7 +3137,8 @@ public class Parser { ...@@ -3137,7 +3137,8 @@ public class Parser {
read("FOR"); read("FOR");
Sequence sequence = readSequence(); Sequence sequence = readSequence();
r = new SequenceValue(sequence); r = new SequenceValue(sequence);
} else if (equalsToken("TIMESTAMP", name) && readIf("WITH")) { } else if (equalsToken("TIMESTAMP", name)) {
if (readIf("WITH")) {
read("TIME"); read("TIME");
read("ZONE"); read("ZONE");
if (currentTokenType != VALUE if (currentTokenType != VALUE
...@@ -3146,8 +3147,20 @@ public class Parser { ...@@ -3146,8 +3147,20 @@ public class Parser {
} }
String timestamp = currentValue.getString(); String timestamp = currentValue.getString();
read(); read();
r = ValueExpression r = ValueExpression.get(ValueTimestampTimeZone.parse(timestamp));
.get(ValueTimestampTimeZone.parse(timestamp)); } else {
if (readIf("WITHOUT")) {
read("TIME");
read("ZONE");
}
if (currentTokenType != VALUE
|| currentValue.getType() != Value.STRING) {
throw getSyntaxError();
}
String timestamp = currentValue.getString();
read();
r = ValueExpression.get(ValueTimestamp.parse(timestamp, database.getMode()));
}
} else if (currentTokenType == VALUE && } else if (currentTokenType == VALUE &&
currentValue.getType() == Value.STRING) { currentValue.getType() == Value.STRING) {
if (equalsToken("DATE", name) || if (equalsToken("DATE", name) ||
...@@ -3160,8 +3173,7 @@ public class Parser { ...@@ -3160,8 +3173,7 @@ public class Parser {
String time = currentValue.getString(); String time = currentValue.getString();
read(); read();
r = ValueExpression.get(ValueTime.parse(time)); r = ValueExpression.get(ValueTime.parse(time));
} else if (equalsToken("TIMESTAMP", name) || } else if (equalsToken("TS", name)) {
equalsToken("TS", name)) {
String timestamp = currentValue.getString(); String timestamp = currentValue.getString();
read(); read();
r = ValueExpression r = ValueExpression
...@@ -4340,6 +4352,10 @@ public class Parser { ...@@ -4340,6 +4352,10 @@ public class Parser {
read("ZONE"); read("ZONE");
original += " WITH TIME ZONE"; original += " WITH TIME ZONE";
} }
} else if (readIf("WITHOUT")) {
read("TIME");
read("ZONE");
original += " WITHOUT TIME ZONE";
} }
} else { } else {
regular = true; regular = true;
......
...@@ -302,7 +302,8 @@ public class DataType { ...@@ -302,7 +302,8 @@ public class DataType {
add(Value.TIMESTAMP, Types.TIMESTAMP, "Timestamp", add(Value.TIMESTAMP, Types.TIMESTAMP, "Timestamp",
createDate(ValueTimestamp.PRECISION, "TIMESTAMP", createDate(ValueTimestamp.PRECISION, "TIMESTAMP",
ValueTimestamp.DEFAULT_SCALE, ValueTimestamp.DISPLAY_SIZE), ValueTimestamp.DEFAULT_SCALE, ValueTimestamp.DISPLAY_SIZE),
new String[]{"TIMESTAMP", "DATETIME", "DATETIME2", "SMALLDATETIME"}, new String[]{"TIMESTAMP", "TIMESTAMP WITHOUT TIME ZONE",
"DATETIME", "DATETIME2", "SMALLDATETIME"},
// 24 for ValueTimestamp, 32 for java.sql.Timestamp // 24 for ValueTimestamp, 32 for java.sql.Timestamp
56 56
); );
......
...@@ -2,3 +2,26 @@ ...@@ -2,3 +2,26 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html). -- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group -- Initial Developer: H2 Group
-- --
CREATE TABLE TEST(T1 TIMESTAMP, T2 TIMESTAMP WITHOUT TIME ZONE);
> ok
INSERT INTO TEST(T1, T2) VALUES (TIMESTAMP '2010-01-01 10:00:00', TIMESTAMP WITHOUT TIME ZONE '2010-01-01 10:00:00');
> update count: 1
SELECT T1, T2, T1 = T2 FROM TEST;
> T1 T2 T1 = T2
> --------------------- --------------------- -------
> 2010-01-01 10:00:00.0 2010-01-01 10:00:00.0 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 93 TIMESTAMP TIMESTAMP
> T2 93 TIMESTAMP TIMESTAMP WITHOUT TIME ZONE
> rows (ordered): 2
DROP TABLE TEST;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论