MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / registerDataTypeTime

Function registerDataTypeTime

src/DataTypes/registerDataTypeDateTime.cpp:495–785  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493}
494
495void registerDataTypeTime(DataTypeFactory & factory)
496{
497 factory.registerDataType("Time", createTime, DataTypeFactory::Case::Insensitive,
498 Documentation{
499 .description = R"DOCS_MD(
500Data type `Time` represents a time with hour, minute, and second components.
501It is independent of any calendar date and is suitable for values which do not need day, months and year components.
502
503Syntax:
504
505``` sql
506Time
507```
508
509Text representation range: [-999:59:59, 999:59:59].
510
511Resolution: 1 second.
512
513## Implementation details {#implementation-details}
514
515**Representation and Performance**.
516Data type `Time` internally stores a signed 32-bit integer that encodes the seconds.
517Values of type `Time` and `DateTime` have the same byte size and thus comparable performance.
518
519**Normalization**.
520When parsing strings to `Time`, the time components are normalized and not validated.
521For example, `25:70:70` is interpreted as `26:11:10`.
522
523**Negative values**.
524Leading minus signs are supported and preserved.
525Negative values typically arise from arithmetic operations on `Time` values.
526For `Time` type, negative inputs are preserved for both text (e.g., `'-01:02:03'`) and numeric inputs (e.g., `-3723`).
527
528**Saturation**.
529The time-of-day component is capped to the range [-999:59:59, 999:59:59].
530Values with hours beyond 999 (or below -999) are represented and round-tripped via text as `999:59:59` (or `-999:59:59`).
531
532**Time zones**.
533`Time` does not support time zones, i.e. `Time` value are interpreted without regional context.
534Specifying a time zone for `Time` as a type parameter or during value creation throws an error.
535Likewise, attempts to apply or change the time zone on `Time` columns are not supported and result in an error.
536`Time` values are not silently reinterpreted under different time zones.
537
538## Examples {#examples}
539
540**1.** Creating a table with a `Time`-type column and inserting data into it:
541
542``` sql
543CREATE TABLE tab
544(
545 `event_id` UInt8,
546 `time` Time
547)
548ENGINE = TinyLog;
549```
550
551``` sql
552-- Parse Time

Callers 1

DataTypeFactoryMethod · 0.85

Calls 1

registerDataTypeMethod · 0.80

Tested by

no test coverage detected