The following content of this documentation page has been machine-translated. But unlike other websites, it is not done on the fly. This translated text lives on GitHub repository alongside main ClickHouse codebase and waits for fellow native speakers to make it more human-readable.
Help ClickHouse documentation by editing this page
Interval类型
表示时间和日期间隔的数据类型家族。 INTERVAL 运算的结果类型。
数据类型值不能存储在表中。
结构:
- 时间间隔作为无符号整数值。
- 时间间隔的类型。
支持的时间间隔类型:
SECOND
MINUTE
HOUR
WEEK
MONTH
QUARTER
YEAR
┌─toTypeName(toIntervalDay(4))─┐
│ IntervalDay │
└──────────────────────────────┘
您可以在与 和 日期时间 类型值的算术运算中使用 Interval
类型值。 例如,您可以将4天添加到当前时间:
│ 2019-10-23 10:58:45 │ 2019-10-27 10:58:45 │
└─────────────────────┴───────────────────────────────┘
不同类型的间隔不能合并。 你不能使用诸如 4 DAY 1 HOUR
的时间间隔. 以小于或等于时间间隔最小单位的单位来指定间隔,例如,时间间隔 1 day and an hour
可以表示为 或 90000 SECOND
.
你不能对 Interval
类型的值执行算术运算,但你可以向 Date
或 DateTime
数据类型的值添加不同类型的时间间隔,例如:
┌───current_date_time─┬─plus(plus(now(), toIntervalDay(4)), toIntervalHour(3))─┐
│ 2019-10-23 11:16:28 │ 2019-10-27 14:16:28 │
└─────────────────────┴────────────────────────────────────────────────────────┘
Received exception from server (version 19.14.1):
Code: 43. DB::Exception: Received from localhost:9000. DB::Exception: Wrong argument types for function plus: if one argument is Interval, then another must be Date or DateTime..
另请参阅
- toInterval 类型转换函数