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

Implement ValueInterval.getSignum(), add(), and subtract()

上级 ea6d213b
......@@ -291,6 +291,23 @@ public class ValueInterval extends Value {
return negative ? -cmp : cmp;
}
@Override
public int getSignum() {
return negative ? -1 : leading == 0L && remaining == 0L ? 0 : 1;
}
@Override
public Value add(Value v) {
return DateTimeUtils.intervalFromAbsolute(getQualifier(),
DateTimeUtils.intervalToAbsolute(this).add(DateTimeUtils.intervalToAbsolute((ValueInterval) v)));
}
@Override
public Value subtract(Value v) {
return DateTimeUtils.intervalFromAbsolute(getQualifier(),
DateTimeUtils.intervalToAbsolute(this).subtract(DateTimeUtils.intervalToAbsolute((ValueInterval) v)));
}
@Override
public Value negate() {
if (leading == 0L && remaining == 0L) {
......
......@@ -28,3 +28,15 @@ select sum(v), sum(v) filter (where v >= 4) from test where v <= 10;
drop table test;
> ok
create table test(v interval day to second);
> ok
insert into test values ('0 1'), ('0 2'), ('0 2'), ('0 2'), ('-0 1'), ('-0 1');
> update count: 6
select sum(v) from test;
>> INTERVAL '0 05:00:00' DAY TO SECOND
drop table test;
> ok
......@@ -15,6 +15,8 @@ select sign(null) en, sign(10) e1, sign(0) e0, sign(-0.1) em1 from test;
> null 1 0 -1
> rows: 1
SELECT SIGN(INTERVAL '-0-1' YEAR TO MONTH) A, SIGN(INTERVAL '0' DAY) B, SIGN(INTERVAL '1' HOUR) C;
> A B C
> -- - -
> -1 0 1
> rows: 1
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论