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

Fix column type for DATE_TRUNC

上级 3a54fe23
...@@ -2197,6 +2197,18 @@ public class Function extends Expression implements FunctionCall { ...@@ -2197,6 +2197,18 @@ public class Function extends Expression implements FunctionCall {
long p; long p;
Expression p0 = args.length < 1 ? null : args[0]; Expression p0 = args.length < 1 ? null : args[0];
switch (info.type) { switch (info.type) {
case DATE_TRUNC: {
Expression p1 = args[1];
t = p1.getType();
if (t == Value.TIMESTAMP_TZ) {
p = d = ValueTimestampTimeZone.DEFAULT_PRECISION;
} else {
t = Value.TIMESTAMP;
p = d = ValueTimestamp.DEFAULT_PRECISION;
}
s = ValueTimestamp.MAXIMUM_SCALE;
break;
}
case IFNULL: case IFNULL:
case NULLIF: case NULLIF:
case COALESCE: case COALESCE:
......
...@@ -113,6 +113,7 @@ public class TestFunctions extends TestDb implements AggregateFunction { ...@@ -113,6 +113,7 @@ public class TestFunctions extends TestDb implements AggregateFunction {
testNvl2(); testNvl2();
testConcatWs(); testConcatWs();
testTruncate(); testTruncate();
testDateTrunc();
testToCharFromDateTime(); testToCharFromDateTime();
testToCharFromNumber(); testToCharFromNumber();
testToCharFromText(); testToCharFromText();
...@@ -1239,6 +1240,23 @@ public class TestFunctions extends TestDb implements AggregateFunction { ...@@ -1239,6 +1240,23 @@ public class TestFunctions extends TestDb implements AggregateFunction {
conn.close(); conn.close();
} }
private void testDateTrunc() throws SQLException {
deleteDb("functions");
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(S VARCHAR, TS TIMESTAMP, D DATE, T TIME, TZ TIMESTAMP WITH TIME ZONE)");
stat.execute("INSERT INTO TEST VALUES ('2010-01-01 10:11:12', '2010-01-01 10:11:12', '2010-01-01', '10:11:12', '2010-01-01 10:11:12Z')");
ResultSetMetaData md = stat.executeQuery("SELECT DATE_TRUNC('HOUR', S), DATE_TRUNC('HOUR', TS),"
+ " DATE_TRUNC('HOUR', D), DATE_TRUNC('HOUR', T), DATE_TRUNC('HOUR', TZ) FROM TEST")
.getMetaData();
assertEquals(Types.TIMESTAMP, md.getColumnType(1));
assertEquals(Types.TIMESTAMP, md.getColumnType(2));
assertEquals(Types.TIMESTAMP, md.getColumnType(3));
assertEquals(Types.TIMESTAMP, md.getColumnType(4));
assertEquals(Types.TIMESTAMP_WITH_TIMEZONE, md.getColumnType(5));
conn.close();
}
private void testTranslate() throws SQLException { private void testTranslate() throws SQLException {
Connection conn = getConnection("functions"); Connection conn = getConnection("functions");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论