| 21 | } |
| 22 | |
| 23 | void registerDataTypeDate32(DataTypeFactory & factory) |
| 24 | { |
| 25 | factory.registerSimpleDataType( |
| 26 | "Date32", [] { return DataTypePtr(std::make_shared<DataTypeDate32>()); }, DataTypeFactory::Case::Insensitive, |
| 27 | Documentation{ |
| 28 | .description = R"DOCS_MD( |
| 29 | A date. Supports the date range same with [DateTime64](../../sql-reference/data-types/datetime64.md). Stored as a signed 32-bit integer in native byte order with the value representing the days since `1900-01-01`. **Important!** 0 represents `1970-01-01`, and negative values represent the days before `1970-01-01`. |
| 30 | |
| 31 | **Examples** |
| 32 | |
| 33 | Creating a table with a `Date32`-type column and inserting data into it: |
| 34 | |
| 35 | ```sql |
| 36 | CREATE TABLE dt32 |
| 37 | ( |
| 38 | `timestamp` Date32, |
| 39 | `event_id` UInt8 |
| 40 | ) |
| 41 | ENGINE = TinyLog; |
| 42 | ``` |
| 43 | |
| 44 | ```sql |
| 45 | -- Parse Date |
| 46 | -- - from string, |
| 47 | -- - from 'small' integer interpreted as number of days since 1970-01-01, and |
| 48 | -- - from 'big' integer interpreted as number of seconds since 1970-01-01. |
| 49 | INSERT INTO dt32 VALUES ('2100-01-01', 1), (47482, 2), (4102444800, 3); |
| 50 | |
| 51 | SELECT * FROM dt32; |
| 52 | ``` |
| 53 | |
| 54 | ```text |
| 55 | ┌──timestamp─┬─event_id─┐ |
| 56 | │ 2100-01-01 │ 1 │ |
| 57 | │ 2100-01-01 │ 2 │ |
| 58 | │ 2100-01-01 │ 3 │ |
| 59 | └────────────┴──────────┘ |
| 60 | ``` |
| 61 | |
| 62 | **See Also** |
| 63 | |
| 64 | - [toDate32](../../sql-reference/functions/type-conversion-functions.md#toDate32) |
| 65 | - [toDate32OrZero](/sql-reference/functions/type-conversion-functions#toDate32OrZero) |
| 66 | - [toDate32OrNull](/sql-reference/functions/type-conversion-functions#toDate32OrNull) |
| 67 | )DOCS_MD", |
| 68 | .syntax = "Date32", |
| 69 | .related = {"Date", "DateTime"}, |
| 70 | }); |
| 71 | } |
| 72 | |
| 73 | } |
no test coverage detected