Help wanted!
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. You can also use the original English version as a reference.
Intervalo
La familia de tipos de datos que representan intervalos de fecha y hora. Los tipos resultantes del INTERVAL operador.
Advertencia
Interval
los valores de tipo de datos no se pueden almacenar en tablas.
Estructura:
- Intervalo de tiempo como un valor entero sin signo.
- Tipo de intervalo.
Tipos de intervalo admitidos:
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEAR
Para cada tipo de intervalo, hay un tipo de datos independiente. Por ejemplo, el DAY
el intervalo corresponde a la IntervalDay
tipo de datos:
SELECT toTypeName(INTERVAL 4 DAY)
┌─toTypeName(toIntervalDay(4))─┐
│ IntervalDay │
└──────────────────────────────┘
Observaciones de uso
Usted puede utilizar Interval
-type valores en operaciones aritméticas con Fecha y FechaHora-type valores. Por ejemplo, puede agregar 4 días a la hora actual:
SELECT now() as current_date_time, current_date_time + INTERVAL 4 DAY
┌───current_date_time─┬─plus(now(), toIntervalDay(4))─┐
│ 2019-10-23 10:58:45 │ 2019-10-27 10:58:45 │
└─────────────────────┴───────────────────────────────┘
Los intervalos con diferentes tipos no se pueden combinar. No puedes usar intervalos como 4 DAY 1 HOUR
. Especifique los intervalos en unidades que son más pequeñas o iguales que la unidad más pequeña del intervalo, por ejemplo, el intervalo 1 day and an hour
se puede expresar como 25 HOUR
o 90000 SECOND
.
No puede realizar operaciones aritméticas con Interval
-type valores, pero puede agregar intervalos de diferentes tipos en consecuencia a los valores en Date
o DateTime
tipos de datos. Por ejemplo:
SELECT now() AS current_date_time, current_date_time + INTERVAL 4 DAY + INTERVAL 3 HOUR
┌───current_date_time─┬─plus(plus(now(), toIntervalDay(4)), toIntervalHour(3))─┐
│ 2019-10-23 11:16:28 │ 2019-10-27 14:16:28 │
└─────────────────────┴────────────────────────────────────────────────────────┘
La siguiente consulta provoca una excepción:
select now() AS current_date_time, current_date_time + (INTERVAL 4 DAY + INTERVAL 3 HOUR)
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..
Ver también
- INTERVAL operador
- ToInterval funciones de conversión de tipo