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 接线员

    数据类型值不能存储在表中。

    结构:

    • 时间间隔作为无符号整数值。
    • 间隔的类型。

    支持的时间间隔类型:

    • SECOND
    • MINUTE
    • HOUR
    • WEEK
    • MONTH
    • QUARTER
    • YEAR
    1. ┌─toTypeName(toIntervalDay(4))─┐
    2. IntervalDay
    3. └──────────────────────────────┘

    您可以使用 Interval-在算术运算类型值 和 日期时间-类型值。 例如,您可以将4天添加到当前时间:

    1. 2019-10-23 10:58:45 2019-10-27 10:58:45
    2. └─────────────────────┴───────────────────────────────┘

    不同类型的间隔不能合并。 你不能使用间隔,如 4 DAY 1 HOUR. 以小于或等于间隔的最小单位的单位指定间隔,例如,间隔 1 day and an hour 间隔可以表示为 或 90000 SECOND.

    你不能执行算术运算 Interval-类型值,但你可以添加不同类型的时间间隔,因此值 DateDateTime 数据类型。 例如:

    1. ┌───current_date_time─┬─plus(plus(now(), toIntervalDay(4)), toIntervalHour(3))─┐
    2. 2019-10-23 11:16:28 2019-10-27 14:16:28
    3. └─────────────────────┴────────────────────────────────────────────────────────┘
    1. Received exception from server (version 19.14.1):
    2. 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..

    另请参阅