From d54d330c6633362aad2ff68becf00247581914d4 Mon Sep 17 00:00:00 2001 From: Nikita Reznikov Date: Tue, 17 Dec 2024 22:05:37 +0300 Subject: [PATCH] [#439] Add support of ISO8601 timestamp strings for DateTime64 column type --- clickhouse_connect/datatypes/temporal.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/clickhouse_connect/datatypes/temporal.py b/clickhouse_connect/datatypes/temporal.py index 39bf0c0..4db5cd7 100644 --- a/clickhouse_connect/datatypes/temporal.py +++ b/clickhouse_connect/datatypes/temporal.py @@ -202,6 +202,18 @@ def _write_column_binary(self, column: Union[Sequence, MutableSequence], dest: b if isinstance(first, int) or self.write_format(ctx) == 'int': if self.nullable: column = [x if x else 0 for x in column] + elif isinstance(first, str) or self.write_format(ctx) == 'str': + original_column = column + column = [] + + for x in original_column: + if not x and self.nullable: + v = 0 + else: + dt = datetime.fromisoformat(x) + v = ((int(dt.timestamp()) * 1000000 + dt.microsecond) * self.prec) // 1000000 + + column.append(v) else: prec = self.prec if self.nullable: