-
CREATE TABLE default.test_tb with table as above, insert one data record as below: insert into TABLE test_tb(id, test_fd1) values(1, toDateTime('2022-03-25 22:35:47.000')) but result is: without toDateTime function: how to correctly insert/update date/datetime field with sql language? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
https://clickhouse.com/docs/en/sql-reference/data-types/datetime64/ https://clickhouse.com/docs/en/operations/settings/settings/#date_time_input_format CREATE TABLE default.test_tb
(
test_fd1 DateTime,
id Int8
)
ENGINE = MergeTree
ORDER BY test_fd1
SETTINGS index_granularity = 8192;
set date_time_input_format='best_effort';
insert into TABLE test_tb(id, test_fd1) values(1, '2022-03-25 22:35:47.000');
insert into TABLE test_tb(id, test_fd1) values(2, cast('2022-03-25 22:35:47.000','DateTime64(3)'));
select * from test_tb;
┌────────────test_fd1─┬─id─┐
│ 2022-03-25 22:35:47 │ 1 │
└─────────────────────┴────┘
┌────────────test_fd1─┬─id─┐
│ 2022-03-25 22:35:47 │ 2 │
└─────────────────────┴────┘
CREATE TABLE default.test_tb1
(
test_fd1 DateTime64(3),
id Int8
)
ENGINE = MergeTree
ORDER BY test_fd1
SETTINGS index_granularity = 8192;
insert into TABLE test_tb1(id, test_fd1) values(1, '2022-03-25 22:35:47.000');
select * from test_tb1;
┌────────────────test_fd1─┬─id─┐
│ 2022-03-25 22:35:47.000 │ 1 │
└─────────────────────────┴────┘ |
Beta Was this translation helpful? Give feedback.
https://clickhouse.com/docs/en/sql-reference/data-types/datetime64/
https://clickhouse.com/docs/en/operations/settings/settings/#date_time_input_format