| 493 | } |
| 494 | |
| 495 | void registerDataTypeTime(DataTypeFactory & factory) |
| 496 | { |
| 497 | factory.registerDataType("Time", createTime, DataTypeFactory::Case::Insensitive, |
| 498 | Documentation{ |
| 499 | .description = R"DOCS_MD( |
| 500 | Data type `Time` represents a time with hour, minute, and second components. |
| 501 | It is independent of any calendar date and is suitable for values which do not need day, months and year components. |
| 502 | |
| 503 | Syntax: |
| 504 | |
| 505 | ``` sql |
| 506 | Time |
| 507 | ``` |
| 508 | |
| 509 | Text representation range: [-999:59:59, 999:59:59]. |
| 510 | |
| 511 | Resolution: 1 second. |
| 512 | |
| 513 | ## Implementation details {#implementation-details} |
| 514 | |
| 515 | **Representation and Performance**. |
| 516 | Data type `Time` internally stores a signed 32-bit integer that encodes the seconds. |
| 517 | Values of type `Time` and `DateTime` have the same byte size and thus comparable performance. |
| 518 | |
| 519 | **Normalization**. |
| 520 | When parsing strings to `Time`, the time components are normalized and not validated. |
| 521 | For example, `25:70:70` is interpreted as `26:11:10`. |
| 522 | |
| 523 | **Negative values**. |
| 524 | Leading minus signs are supported and preserved. |
| 525 | Negative values typically arise from arithmetic operations on `Time` values. |
| 526 | For `Time` type, negative inputs are preserved for both text (e.g., `'-01:02:03'`) and numeric inputs (e.g., `-3723`). |
| 527 | |
| 528 | **Saturation**. |
| 529 | The time-of-day component is capped to the range [-999:59:59, 999:59:59]. |
| 530 | Values 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. |
| 534 | Specifying a time zone for `Time` as a type parameter or during value creation throws an error. |
| 535 | Likewise, 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 |
| 543 | CREATE TABLE tab |
| 544 | ( |
| 545 | `event_id` UInt8, |
| 546 | `time` Time |
| 547 | ) |
| 548 | ENGINE = TinyLog; |
| 549 | ``` |
| 550 | |
| 551 | ``` sql |
| 552 | -- Parse Time |
no test coverage detected