Skip to content

Two Core types cannot be bound through the DBAPI: LargeBinary (no PEP 249 Binary constructor) and Time #919

Description

@ChrisGVE

Versions

  • clickhouse-connect 1.6.0
  • SQLAlchemy 2.0.51
  • Python 3.12.9, macOS
  • Server: clickhouse/clickhouse-server:25.3

Two Core types can't be bound through the driver. Neither is a ClickHouse limitation — the database handles both fine — so I'm reporting them together, though the causes are different.

1. LargeBinary — the PEP 249 Binary constructor is missing

clickhouse_connect.dbapi doesn't define Binary. SQLAlchemy's bind processor calls it and gets:

AttributeError: module 'clickhouse_connect.dbapi' has no attribute 'Binary'

before any statement is sent. PEP 249 lists Binary among the constructors a module must supply, alongside Date, Time, Timestamp and the rest.

ClickHouse stores binary perfectly well — String holds arbitrary bytes — so this is purely the DBAPI layer being incomplete.

2. Time — the column is created and then refuses every value

TIME is a real ClickHouse type, stored as an integer number of seconds, and the column gets created without complaint. But a Python time reaches the server as the bare literal 14:30:00 where an Int64 is expected, and the insert fails to parse.

A column that exists and rejects every value is a slightly worse outcome than one that couldn't be created, because it looks fine until you write to it. I've had to declare Time unstorable on this dialect for that reason.

Suggested fixes

For the first: add Binary to clickhouse_connect.dbapi — it can be as thin as Binary = bytes, which is what several other drivers do.

For the second: convert a datetime.time to seconds since midnight in the bind path, matching the storage the server expects.

Happy to test either against my setup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions