We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 469c8b2 commit e8698a6Copy full SHA for e8698a6
ibis/backends/clickhouse/registry.py
@@ -371,11 +371,14 @@ def _literal(translator, expr):
371
return _interval_format(translator, expr)
372
elif isinstance(expr, ir.TimestampValue):
373
if isinstance(value, datetime):
374
- if value.microsecond != 0:
375
- msg = 'Unsupported subsecond accuracy {}'
376
- raise ValueError(msg.format(value))
377
- value = value.strftime('%Y-%m-%d %H:%M:%S')
378
- return f"toDateTime('{value!s}')"
+ micros = value.microsecond
+ value = repr(value.isoformat())
+
+ if micros % 1000:
+ return f"toDateTime64({value}, 6)"
379
+ elif micros // 1000:
380
+ return f"toDateTime64({value}, 3)"
381
+ return f"toDateTime({value})"
382
elif isinstance(expr, ir.DateValue):
383
if isinstance(value, date):
384
value = value.strftime('%Y-%m-%d')
0 commit comments