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

Add DATEADD return type detection

上级 3bc437a2
......@@ -2196,6 +2196,43 @@ public class Function extends Expression implements FunctionCall {
long p;
Expression p0 = args.length < 1 ? null : args[0];
switch (info.type) {
case DATE_ADD: {
t = Value.TIMESTAMP;
p = d = ValueTimestamp.DEFAULT_PRECISION;
s = ValueTimestamp.MAXIMUM_SCALE;
if (p0.isConstant()) {
Expression p2 = args[2];
switch (p2.getType()) {
case Value.TIME:
t = Value.TIME;
p = d = ValueTime.DEFAULT_PRECISION;
break;
case Value.DATE: {
int field = DateTimeFunctions.getDatePart(p0.getValue(session).getString());
switch (field) {
case HOUR:
case MINUTE:
case SECOND:
case EPOCH:
case MILLISECOND:
case MICROSECOND:
case NANOSECOND:
// TIMESTAMP result
break;
default:
t = Value.DATE;
p = d = ValueDate.PRECISION;
s = 0;
}
break;
}
case Value.TIMESTAMP_TZ:
t = Value.TIMESTAMP_TZ;
p = d = ValueTimestampTimeZone.DEFAULT_PRECISION;
}
}
break;
}
case EXTRACT: {
if (p0.isConstant() && DateTimeFunctions.getDatePart(p0.getValue(session).getString()) == Function.EPOCH) {
t = Value.DECIMAL;
......
......@@ -107,3 +107,6 @@ SELECT TIMESTAMPADD('TIMEZONE_MINUTE', -45, TIMESTAMP WITH TIME ZONE '2010-01-01
SELECT DATEADD(HOUR, 1, TIME '23:00:00');
>> 00:00:00
SELECT D FROM (SELECT '2010-01-01' D) WHERE D IN (SELECT D1 - 1 FROM (SELECT DATE '2010-01-02' D1));
>> 2010-01-01
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论