Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
eae51e9e
提交
eae51e9e
authored
8月 14, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement casts between INTERVAL types
上级
c76da8f2
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
465 行增加
和
0 行删除
+465
-0
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+111
-0
Value.java
h2/src/main/org/h2/value/Value.java
+39
-0
interval.sql
h2/src/test/org/h2/test/scripts/datatypes/interval.sql
+315
-0
没有找到文件。
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
eae51e9e
...
...
@@ -6,14 +6,17 @@
*/
package
org
.
h2
.
util
;
import
java.math.BigInteger
;
import
java.sql.Date
;
import
java.sql.Time
;
import
java.sql.Timestamp
;
import
java.util.Calendar
;
import
java.util.GregorianCalendar
;
import
java.util.TimeZone
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.IntervalQualifier
;
import
org.h2.engine.Mode
;
import
org.h2.message.DbException
;
import
org.h2.value.Value
;
import
org.h2.value.ValueDate
;
import
org.h2.value.ValueInterval
;
...
...
@@ -1746,4 +1749,112 @@ public class DateTimeUtils {
return
nanosOfDay
-
mod
;
}
/**
* Converts interval value to an absolute value.
*
* @param interval the interval value
* @return absolute value in months for year-month intervals,
* in nanoseconds for day-time intervals
*/
public
static
BigInteger
intervalToAbsolute
(
ValueInterval
interval
)
{
switch
(
interval
.
getQualifier
())
{
case
YEAR:
return
BigInteger
.
valueOf
(
interval
.
getLeading
()).
multiply
(
BigInteger
.
valueOf
(
12
));
case
MONTH:
return
BigInteger
.
valueOf
(
interval
.
getLeading
());
case
DAY:
return
BigInteger
.
valueOf
(
interval
.
getLeading
()).
multiply
(
BigInteger
.
valueOf
(
NANOS_PER_DAY
));
case
HOUR:
return
BigInteger
.
valueOf
(
interval
.
getLeading
()).
multiply
(
BigInteger
.
valueOf
(
3_600_000_000_000L
));
case
MINUTE:
return
BigInteger
.
valueOf
(
interval
.
getLeading
()).
multiply
(
BigInteger
.
valueOf
(
60_000_000_000L
));
case
SECOND:
return
intervalToAbsolute
(
interval
,
1_000_000_000
);
case
YEAR_TO_MONTH:
return
intervalToAbsolute
(
interval
,
12
);
case
DAY_TO_HOUR:
return
intervalToAbsolute
(
interval
,
24
,
3_600_000_000_000L
);
case
DAY_TO_MINUTE:
return
intervalToAbsolute
(
interval
,
24
*
60
,
60_000_000_000L
);
case
DAY_TO_SECOND:
return
intervalToAbsolute
(
interval
,
NANOS_PER_DAY
);
case
HOUR_TO_MINUTE:
return
intervalToAbsolute
(
interval
,
60
,
60_000_000_000L
);
case
HOUR_TO_SECOND:
return
intervalToAbsolute
(
interval
,
3_600_000_000_000L
);
case
MINUTE_TO_SECOND:
return
intervalToAbsolute
(
interval
,
60_000_000_000L
);
default
:
throw
new
IllegalArgumentException
();
}
}
private
static
BigInteger
intervalToAbsolute
(
ValueInterval
interval
,
long
multiplier
,
long
totalMultiplier
)
{
return
intervalToAbsolute
(
interval
,
multiplier
).
multiply
(
BigInteger
.
valueOf
(
totalMultiplier
));
}
private
static
BigInteger
intervalToAbsolute
(
ValueInterval
interval
,
long
multiplier
)
{
long
leading
=
interval
.
getLeading
(),
remaining
=
interval
.
getRemaining
();
if
(
leading
<
0
)
{
remaining
=
-
remaining
;
}
return
BigInteger
.
valueOf
(
leading
).
multiply
(
BigInteger
.
valueOf
(
multiplier
)).
add
(
BigInteger
.
valueOf
(
remaining
));
}
/**
* Converts absolute value to an interval value.
*
* @param qualifier the qualifier of interval
* @param absolute absolute value in months for year-month intervals,
* in nanoseconds for day-time intervals
* @return the interval value
*/
public
static
ValueInterval
intervalFromAbsolute
(
IntervalQualifier
qualifier
,
BigInteger
absolute
)
{
switch
(
qualifier
)
{
case
YEAR:
return
ValueInterval
.
from
(
qualifier
,
absolute
.
divide
(
BigInteger
.
valueOf
(
12
)).
longValue
(),
0
);
case
MONTH:
return
ValueInterval
.
from
(
qualifier
,
leadingExact
(
absolute
),
0
);
case
DAY:
return
ValueInterval
.
from
(
qualifier
,
leadingExact
(
absolute
.
divide
(
BigInteger
.
valueOf
(
NANOS_PER_DAY
))),
0
);
case
HOUR:
return
ValueInterval
.
from
(
qualifier
,
leadingExact
(
absolute
.
divide
(
BigInteger
.
valueOf
(
3_600_000_000_000L
))),
0
);
case
MINUTE:
return
ValueInterval
.
from
(
qualifier
,
leadingExact
(
absolute
.
divide
(
BigInteger
.
valueOf
(
60_000_000_000L
))),
0
);
case
SECOND:
return
intervalFromAbsolute
(
qualifier
,
absolute
,
1_000_000_000
);
case
YEAR_TO_MONTH:
return
intervalFromAbsolute
(
qualifier
,
absolute
,
12
);
case
DAY_TO_HOUR:
return
intervalFromAbsolute
(
qualifier
,
absolute
.
divide
(
BigInteger
.
valueOf
(
3_600_000_000_000L
)),
24
);
case
DAY_TO_MINUTE:
return
intervalFromAbsolute
(
qualifier
,
absolute
.
divide
(
BigInteger
.
valueOf
(
60_000_000_000L
)),
24
*
60
);
case
DAY_TO_SECOND:
return
intervalFromAbsolute
(
qualifier
,
absolute
,
NANOS_PER_DAY
);
case
HOUR_TO_MINUTE:
return
intervalFromAbsolute
(
qualifier
,
absolute
.
divide
(
BigInteger
.
valueOf
(
60_000_000_000L
)),
60
);
case
HOUR_TO_SECOND:
return
intervalFromAbsolute
(
qualifier
,
absolute
,
3_600_000_000_000L
);
case
MINUTE_TO_SECOND:
return
intervalFromAbsolute
(
qualifier
,
absolute
,
60_000_000_000L
);
default
:
throw
new
IllegalArgumentException
();
}
}
private
static
ValueInterval
intervalFromAbsolute
(
IntervalQualifier
qualifier
,
BigInteger
absolute
,
long
divisor
)
{
BigInteger
[]
dr
=
absolute
.
divideAndRemainder
(
BigInteger
.
valueOf
(
divisor
));
return
ValueInterval
.
from
(
qualifier
,
leadingExact
(
dr
[
0
]),
Math
.
abs
(
dr
[
1
].
longValue
()));
}
private
static
long
leadingExact
(
BigInteger
absolute
)
{
if
(
absolute
.
compareTo
(
BigInteger
.
valueOf
(
999_999_999_999_999_999L
))
>
0
||
absolute
.
compareTo
(
BigInteger
.
valueOf
(-
999_999_999_999_999_999L
))
<
0
)
{
throw
DbException
.
get
(
ErrorCode
.
NUMERIC_VALUE_OUT_OF_RANGE_1
,
absolute
.
toString
());
}
return
absolute
.
longValue
();
}
}
h2/src/main/org/h2/value/Value.java
浏览文件 @
eae51e9e
...
...
@@ -20,6 +20,7 @@ import java.sql.Time;
import
java.sql.Timestamp
;
import
java.sql.Types
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.IntervalQualifier
;
import
org.h2.engine.Mode
;
import
org.h2.engine.SysProperties
;
import
org.h2.message.DbException
;
...
...
@@ -1148,6 +1149,44 @@ public abstract class Value {
}
break
;
}
case
Value
.
INTERVAL_YEAR
:
case
Value
.
INTERVAL_MONTH
:
case
Value
.
INTERVAL_YEAR_TO_MONTH
:
switch
(
getType
())
{
case
Value
.
INTERVAL_YEAR
:
case
Value
.
INTERVAL_MONTH
:
case
Value
.
INTERVAL_YEAR_TO_MONTH
:
return
DateTimeUtils
.
intervalFromAbsolute
(
IntervalQualifier
.
valueOf
(
targetType
-
Value
.
INTERVAL_YEAR
),
DateTimeUtils
.
intervalToAbsolute
((
ValueInterval
)
this
));
}
break
;
case
Value
.
INTERVAL_DAY
:
case
Value
.
INTERVAL_HOUR
:
case
Value
.
INTERVAL_MINUTE
:
case
Value
.
INTERVAL_SECOND
:
case
Value
.
INTERVAL_DAY_TO_HOUR
:
case
Value
.
INTERVAL_DAY_TO_MINUTE
:
case
Value
.
INTERVAL_DAY_TO_SECOND
:
case
Value
.
INTERVAL_HOUR_TO_MINUTE
:
case
Value
.
INTERVAL_HOUR_TO_SECOND
:
case
Value
.
INTERVAL_MINUTE_TO_SECOND
:
switch
(
getType
())
{
case
Value
.
INTERVAL_DAY
:
case
Value
.
INTERVAL_HOUR
:
case
Value
.
INTERVAL_MINUTE
:
case
Value
.
INTERVAL_SECOND
:
case
Value
.
INTERVAL_DAY_TO_HOUR
:
case
Value
.
INTERVAL_DAY_TO_MINUTE
:
case
Value
.
INTERVAL_DAY_TO_SECOND
:
case
Value
.
INTERVAL_HOUR_TO_MINUTE
:
case
Value
.
INTERVAL_HOUR_TO_SECOND
:
case
Value
.
INTERVAL_MINUTE_TO_SECOND
:
return
DateTimeUtils
.
intervalFromAbsolute
(
IntervalQualifier
.
valueOf
(
targetType
-
Value
.
INTERVAL_YEAR
),
DateTimeUtils
.
intervalToAbsolute
((
ValueInterval
)
this
));
}
break
;
}
// conversion by parsing the string value
String
s
=
getString
();
...
...
h2/src/test/org/h2/test/scripts/datatypes/interval.sql
浏览文件 @
eae51e9e
...
...
@@ -117,3 +117,318 @@ SELECT J11, J12, J12 FROM TEST ORDER BY ID;
DROP
TABLE
TEST
;
>
ok
-- Year-month casts
SELECT
CAST
(
INTERVAL
'-10'
YEAR
AS
INTERVAL
MONTH
);
>>
INTERVAL
'-120'
MONTH
SELECT
CAST
(
INTERVAL
'-10'
YEAR
AS
INTERVAL
YEAR
TO
MONTH
);
>>
INTERVAL
'-10-0'
YEAR
TO
MONTH
SELECT
CAST
(
INTERVAL
'-20'
MONTH
AS
INTERVAL
YEAR
);
>>
INTERVAL
'-1'
YEAR
SELECT
CAST
(
INTERVAL
'-20'
MONTH
AS
INTERVAL
YEAR
TO
MONTH
);
>>
INTERVAL
'-1-8'
YEAR
TO
MONTH
SELECT
CAST
(
INTERVAL
'-20-10'
YEAR
TO
MONTH
AS
INTERVAL
YEAR
);
>>
INTERVAL
'-20'
YEAR
SELECT
CAST
(
INTERVAL
'-20-10'
YEAR
TO
MONTH
AS
INTERVAL
MONTH
);
>>
INTERVAL
'-250'
MONTH
-- Day-time casts: DAY
SELECT
CAST
(
INTERVAL
'-10'
DAY
AS
INTERVAL
HOUR
);
>>
INTERVAL
'-240'
HOUR
SELECT
CAST
(
INTERVAL
'-10'
DAY
AS
INTERVAL
MINUTE
);
>>
INTERVAL
'-14400'
MINUTE
SELECT
CAST
(
INTERVAL
'-10'
DAY
AS
INTERVAL
SECOND
);
>>
INTERVAL
'-864000'
SECOND
SELECT
CAST
(
INTERVAL
'-10'
DAY
AS
INTERVAL
DAY
TO
HOUR
);
>>
INTERVAL
'-10 00'
DAY
TO
HOUR
SELECT
CAST
(
INTERVAL
'-10'
DAY
AS
INTERVAL
DAY
TO
MINUTE
);
>>
INTERVAL
'-10 00:00'
DAY
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-10'
DAY
AS
INTERVAL
DAY
TO
SECOND
);
>>
INTERVAL
'-10 00:00:00'
DAY
TO
SECOND
SELECT
CAST
(
INTERVAL
'-10'
DAY
AS
INTERVAL
HOUR
TO
MINUTE
);
>>
INTERVAL
'-240:00'
HOUR
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-10'
DAY
AS
INTERVAL
HOUR
TO
SECOND
);
>>
INTERVAL
'-240:00:00'
HOUR
TO
SECOND
SELECT
CAST
(
INTERVAL
'-10'
DAY
AS
INTERVAL
MINUTE
TO
SECOND
);
>>
INTERVAL
'-14400:00'
MINUTE
TO
SECOND
-- Day-time casts: HOUR
SELECT
CAST
(
INTERVAL
'-30'
HOUR
AS
INTERVAL
DAY
);
>>
INTERVAL
'-1'
DAY
SELECT
CAST
(
INTERVAL
'-30'
HOUR
AS
INTERVAL
MINUTE
);
>>
INTERVAL
'-1800'
MINUTE
SELECT
CAST
(
INTERVAL
'-30'
HOUR
AS
INTERVAL
SECOND
);
>>
INTERVAL
'-108000'
SECOND
SELECT
CAST
(
INTERVAL
'-30'
HOUR
AS
INTERVAL
DAY
TO
HOUR
);
>>
INTERVAL
'-1 06'
DAY
TO
HOUR
SELECT
CAST
(
INTERVAL
'-30'
HOUR
AS
INTERVAL
DAY
TO
MINUTE
);
>>
INTERVAL
'-1 06:00'
DAY
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-30'
HOUR
AS
INTERVAL
DAY
TO
SECOND
);
>>
INTERVAL
'-1 06:00:00'
DAY
TO
SECOND
SELECT
CAST
(
INTERVAL
'-30'
HOUR
AS
INTERVAL
HOUR
TO
MINUTE
);
>>
INTERVAL
'-30:00'
HOUR
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-30'
HOUR
AS
INTERVAL
HOUR
TO
SECOND
);
>>
INTERVAL
'-30:00:00'
HOUR
TO
SECOND
SELECT
CAST
(
INTERVAL
'-30'
HOUR
AS
INTERVAL
MINUTE
TO
SECOND
);
>>
INTERVAL
'-1800:00'
MINUTE
TO
SECOND
-- Day-time casts: MINUTE
SELECT
CAST
(
INTERVAL
'-1570'
MINUTE
AS
INTERVAL
DAY
);
>>
INTERVAL
'-1'
DAY
SELECT
CAST
(
INTERVAL
'-1570'
MINUTE
AS
INTERVAL
HOUR
);
>>
INTERVAL
'-26'
HOUR
SELECT
CAST
(
INTERVAL
'-1570'
MINUTE
AS
INTERVAL
SECOND
);
>>
INTERVAL
'-94200'
SECOND
SELECT
CAST
(
INTERVAL
'-1570'
MINUTE
AS
INTERVAL
DAY
TO
HOUR
);
>>
INTERVAL
'-1 02'
DAY
TO
HOUR
SELECT
CAST
(
INTERVAL
'-1570'
MINUTE
AS
INTERVAL
DAY
TO
MINUTE
);
>>
INTERVAL
'-1 02:10'
DAY
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-1570'
MINUTE
AS
INTERVAL
DAY
TO
SECOND
);
>>
INTERVAL
'-1 02:10:00'
DAY
TO
SECOND
SELECT
CAST
(
INTERVAL
'-1570'
MINUTE
AS
INTERVAL
HOUR
TO
MINUTE
);
>>
INTERVAL
'-26:10'
HOUR
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-1570'
MINUTE
AS
INTERVAL
HOUR
TO
SECOND
);
>>
INTERVAL
'-26:10:00'
HOUR
TO
SECOND
SELECT
CAST
(
INTERVAL
'-1570'
MINUTE
AS
INTERVAL
MINUTE
TO
SECOND
);
>>
INTERVAL
'-1570:00'
MINUTE
TO
SECOND
-- Day-time casts: SECOND
SELECT
CAST
(
INTERVAL
'-93784.123456789'
SECOND
AS
INTERVAL
DAY
);
>>
INTERVAL
'-1'
DAY
SELECT
CAST
(
INTERVAL
'-93784.123456789'
SECOND
AS
INTERVAL
HOUR
);
>>
INTERVAL
'-26'
HOUR
SELECT
CAST
(
INTERVAL
'-93784.123456789'
SECOND
AS
INTERVAL
MINUTE
);
>>
INTERVAL
'-1563'
MINUTE
SELECT
CAST
(
INTERVAL
'-93784.123456789'
SECOND
AS
INTERVAL
DAY
TO
HOUR
);
>>
INTERVAL
'-1 02'
DAY
TO
HOUR
SELECT
CAST
(
INTERVAL
'-93784.123456789'
SECOND
AS
INTERVAL
DAY
TO
MINUTE
);
>>
INTERVAL
'-1 02:03'
DAY
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-93784.123456789'
SECOND
AS
INTERVAL
DAY
TO
SECOND
);
>>
INTERVAL
'-1 02:03:04.123457'
DAY
TO
SECOND
SELECT
CAST
(
INTERVAL
'-93784.123456789'
SECOND
AS
INTERVAL
HOUR
TO
MINUTE
);
>>
INTERVAL
'-26:03'
HOUR
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-93784.123456789'
SECOND
AS
INTERVAL
HOUR
TO
SECOND
);
>>
INTERVAL
'-26:03:04.123457'
HOUR
TO
SECOND
SELECT
CAST
(
INTERVAL
'-93784.123456789'
SECOND
AS
INTERVAL
MINUTE
TO
SECOND
);
>>
INTERVAL
'-1563:04.123457'
MINUTE
TO
SECOND
-- Day-time casts: DAY TO HOUR
SELECT
CAST
(
INTERVAL
'-1 2'
DAY
TO
HOUR
AS
INTERVAL
DAY
);
>>
INTERVAL
'-1'
DAY
SELECT
CAST
(
INTERVAL
'-1 2'
DAY
TO
HOUR
AS
INTERVAL
HOUR
);
>>
INTERVAL
'-26'
HOUR
SELECT
CAST
(
INTERVAL
'-1 2'
DAY
TO
HOUR
AS
INTERVAL
MINUTE
);
>>
INTERVAL
'-1560'
MINUTE
SELECT
CAST
(
INTERVAL
'-1 2'
DAY
TO
HOUR
AS
INTERVAL
SECOND
);
>>
INTERVAL
'-93600'
SECOND
SELECT
CAST
(
INTERVAL
'-1 2'
DAY
TO
HOUR
AS
INTERVAL
DAY
TO
MINUTE
);
>>
INTERVAL
'-1 02:00'
DAY
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-1 2'
DAY
TO
HOUR
AS
INTERVAL
DAY
TO
SECOND
);
>>
INTERVAL
'-1 02:00:00'
DAY
TO
SECOND
SELECT
CAST
(
INTERVAL
'-1 2'
DAY
TO
HOUR
AS
INTERVAL
HOUR
TO
MINUTE
);
>>
INTERVAL
'-26:00'
HOUR
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-1 2'
DAY
TO
HOUR
AS
INTERVAL
HOUR
TO
SECOND
);
>>
INTERVAL
'-26:00:00'
HOUR
TO
SECOND
SELECT
CAST
(
INTERVAL
'-1 2'
DAY
TO
HOUR
AS
INTERVAL
MINUTE
TO
SECOND
);
>>
INTERVAL
'-1560:00'
MINUTE
TO
SECOND
-- Day-time casts: DAY TO MINUTE
SELECT
CAST
(
INTERVAL
'-1 2:3'
DAY
TO
MINUTE
AS
INTERVAL
DAY
);
>>
INTERVAL
'-1'
DAY
SELECT
CAST
(
INTERVAL
'-1 2:3'
DAY
TO
MINUTE
AS
INTERVAL
HOUR
);
>>
INTERVAL
'-26'
HOUR
SELECT
CAST
(
INTERVAL
'-1 2:3'
DAY
TO
MINUTE
AS
INTERVAL
MINUTE
);
>>
INTERVAL
'-1563'
MINUTE
SELECT
CAST
(
INTERVAL
'-1 2:3'
DAY
TO
MINUTE
AS
INTERVAL
SECOND
);
>>
INTERVAL
'-93780'
SECOND
SELECT
CAST
(
INTERVAL
'-1 2:3'
DAY
TO
MINUTE
AS
INTERVAL
DAY
TO
HOUR
);
>>
INTERVAL
'-1 02'
DAY
TO
HOUR
SELECT
CAST
(
INTERVAL
'-1 2:3'
DAY
TO
MINUTE
AS
INTERVAL
DAY
TO
SECOND
);
>>
INTERVAL
'-1 02:03:00'
DAY
TO
SECOND
SELECT
CAST
(
INTERVAL
'-1 2:3'
DAY
TO
MINUTE
AS
INTERVAL
HOUR
TO
MINUTE
);
>>
INTERVAL
'-26:03'
HOUR
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-1 2:3'
DAY
TO
MINUTE
AS
INTERVAL
HOUR
TO
SECOND
);
>>
INTERVAL
'-26:03:00'
HOUR
TO
SECOND
SELECT
CAST
(
INTERVAL
'-1 2:3'
DAY
TO
MINUTE
AS
INTERVAL
MINUTE
TO
SECOND
);
>>
INTERVAL
'-1563:00'
MINUTE
TO
SECOND
-- Day-time casts: DAY TO SECOND
SELECT
CAST
(
INTERVAL
'-1 2:3:4.123456789'
DAY
TO
SECOND
AS
INTERVAL
DAY
);
>>
INTERVAL
'-1'
DAY
SELECT
CAST
(
INTERVAL
'-1 2:3:4.123456789'
DAY
TO
SECOND
AS
INTERVAL
HOUR
);
>>
INTERVAL
'-26'
HOUR
SELECT
CAST
(
INTERVAL
'-1 2:3:4.123456789'
DAY
TO
SECOND
AS
INTERVAL
MINUTE
);
>>
INTERVAL
'-1563'
MINUTE
SELECT
CAST
(
INTERVAL
'-1 2:3:4.123456789'
DAY
TO
SECOND
AS
INTERVAL
SECOND
);
>>
INTERVAL
'-93784.123457'
SECOND
SELECT
CAST
(
INTERVAL
'-1 2:3:4.123456789'
DAY
TO
SECOND
AS
INTERVAL
DAY
TO
HOUR
);
>>
INTERVAL
'-1 02'
DAY
TO
HOUR
SELECT
CAST
(
INTERVAL
'-1 2:3:4.123456789'
DAY
TO
SECOND
AS
INTERVAL
DAY
TO
MINUTE
);
>>
INTERVAL
'-1 02:03'
DAY
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-1 2:3:4.123456789'
DAY
TO
SECOND
AS
INTERVAL
HOUR
TO
MINUTE
);
>>
INTERVAL
'-26:03'
HOUR
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-1 2:3:4.123456789'
DAY
TO
SECOND
AS
INTERVAL
HOUR
TO
SECOND
);
>>
INTERVAL
'-26:03:04.123457'
HOUR
TO
SECOND
SELECT
CAST
(
INTERVAL
'-1 2:3:4.123456789'
DAY
TO
SECOND
AS
INTERVAL
MINUTE
TO
SECOND
);
>>
INTERVAL
'-1563:04.123457'
MINUTE
TO
SECOND
-- Day-time casts: HOUR TO MINUTE
SELECT
CAST
(
INTERVAL
'-30:2'
HOUR
TO
MINUTE
AS
INTERVAL
DAY
);
>>
INTERVAL
'-1'
DAY
SELECT
CAST
(
INTERVAL
'-30:2'
HOUR
TO
MINUTE
AS
INTERVAL
HOUR
);
>>
INTERVAL
'-30'
HOUR
SELECT
CAST
(
INTERVAL
'-30:2'
HOUR
TO
MINUTE
AS
INTERVAL
MINUTE
);
>>
INTERVAL
'-1802'
MINUTE
SELECT
CAST
(
INTERVAL
'-30:2'
HOUR
TO
MINUTE
AS
INTERVAL
SECOND
);
>>
INTERVAL
'-108120'
SECOND
SELECT
CAST
(
INTERVAL
'-30:2'
HOUR
TO
MINUTE
AS
INTERVAL
DAY
TO
HOUR
);
>>
INTERVAL
'-1 06'
DAY
TO
HOUR
SELECT
CAST
(
INTERVAL
'-30:2'
HOUR
TO
MINUTE
AS
INTERVAL
DAY
TO
MINUTE
);
>>
INTERVAL
'-1 06:02'
DAY
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-30:2'
HOUR
TO
MINUTE
AS
INTERVAL
DAY
TO
SECOND
);
>>
INTERVAL
'-1 06:02:00'
DAY
TO
SECOND
SELECT
CAST
(
INTERVAL
'-30:2'
HOUR
TO
MINUTE
AS
INTERVAL
HOUR
TO
SECOND
);
>>
INTERVAL
'-30:02:00'
HOUR
TO
SECOND
SELECT
CAST
(
INTERVAL
'-30:2'
HOUR
TO
MINUTE
AS
INTERVAL
MINUTE
TO
SECOND
);
>>
INTERVAL
'-1802:00'
MINUTE
TO
SECOND
-- Day-time casts: HOUR TO SECOND
SELECT
CAST
(
INTERVAL
'-30:2:4.123456789'
HOUR
TO
SECOND
AS
INTERVAL
DAY
);
>>
INTERVAL
'-1'
DAY
SELECT
CAST
(
INTERVAL
'-30:2:4.123456789'
HOUR
TO
SECOND
AS
INTERVAL
HOUR
);
>>
INTERVAL
'-30'
HOUR
SELECT
CAST
(
INTERVAL
'-30:2:4.123456789'
HOUR
TO
SECOND
AS
INTERVAL
MINUTE
);
>>
INTERVAL
'-1802'
MINUTE
SELECT
CAST
(
INTERVAL
'-30:2:4.123456789'
HOUR
TO
SECOND
AS
INTERVAL
SECOND
);
>>
INTERVAL
'-108124.123457'
SECOND
SELECT
CAST
(
INTERVAL
'-30:2:4.123456789'
HOUR
TO
SECOND
AS
INTERVAL
DAY
TO
HOUR
);
>>
INTERVAL
'-1 06'
DAY
TO
HOUR
SELECT
CAST
(
INTERVAL
'-30:2:4.123456789'
HOUR
TO
SECOND
AS
INTERVAL
DAY
TO
MINUTE
);
>>
INTERVAL
'-1 06:02'
DAY
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-30:2:4.123456789'
HOUR
TO
SECOND
AS
INTERVAL
DAY
TO
SECOND
);
>>
INTERVAL
'-1 06:02:04.123457'
DAY
TO
SECOND
SELECT
CAST
(
INTERVAL
'-30:2:4.123456789'
HOUR
TO
SECOND
AS
INTERVAL
HOUR
TO
MINUTE
);
>>
INTERVAL
'-30:02'
HOUR
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-30:2:4.123456789'
HOUR
TO
SECOND
AS
INTERVAL
MINUTE
TO
SECOND
);
>>
INTERVAL
'-1802:04.123457'
MINUTE
TO
SECOND
-- Day-time casts: MINUTE TO SECOND
SELECT
CAST
(
INTERVAL
'-1803:4.123456789'
MINUTE
TO
SECOND
AS
INTERVAL
DAY
);
>>
INTERVAL
'-1'
DAY
SELECT
CAST
(
INTERVAL
'-1803:4.123456789'
MINUTE
TO
SECOND
AS
INTERVAL
HOUR
);
>>
INTERVAL
'-30'
HOUR
SELECT
CAST
(
INTERVAL
'-1803:4.123456789'
MINUTE
TO
SECOND
AS
INTERVAL
MINUTE
);
>>
INTERVAL
'-1803'
MINUTE
SELECT
CAST
(
INTERVAL
'-1803:4.123456789'
MINUTE
TO
SECOND
AS
INTERVAL
SECOND
);
>>
INTERVAL
'-108184.123457'
SECOND
SELECT
CAST
(
INTERVAL
'-1803:4.123456789'
MINUTE
TO
SECOND
AS
INTERVAL
DAY
TO
HOUR
);
>>
INTERVAL
'-1 06'
DAY
TO
HOUR
SELECT
CAST
(
INTERVAL
'-1803:4.123456789'
MINUTE
TO
SECOND
AS
INTERVAL
DAY
TO
MINUTE
);
>>
INTERVAL
'-1 06:03'
DAY
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-1803:4.123456789'
MINUTE
TO
SECOND
AS
INTERVAL
DAY
TO
SECOND
);
>>
INTERVAL
'-1 06:03:04.123457'
DAY
TO
SECOND
SELECT
CAST
(
INTERVAL
'-1803:4.123456789'
MINUTE
TO
SECOND
AS
INTERVAL
HOUR
TO
MINUTE
);
>>
INTERVAL
'-30:03'
HOUR
TO
MINUTE
SELECT
CAST
(
INTERVAL
'-1803:4.123456789'
MINUTE
TO
SECOND
AS
INTERVAL
HOUR
TO
SECOND
);
>>
INTERVAL
'-30:03:04.123457'
HOUR
TO
SECOND
-- Cast with fractional seconds precision
SELECT
CAST
(
INTERVAL
'10:11.123456789'
MINUTE
TO
SECOND
AS
INTERVAL
SECOND
(
3
,
9
));
>>
INTERVAL
'611.123456789'
SECOND
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论