ClickHouse Connect includes a SQLAlchemy dialect (Documentation Index
Fetch the complete documentation index at: https://private-7c7dfe99-page-updates.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
clickhousedb) built on top of the core driver. It targets SQLAlchemy Core APIs and supports SQLAlchemy 1.4.40+ and 2.0.x.
Connect with SQLAlchemy
Create an engine using eitherclickhousedb:// or clickhousedb+connect:// URLs. Query parameters map to ClickHouse settings, client options, and HTTP/TLS transport options.
- ClickHouse settings: pass as query parameters (for example,
use_skip_indexes=0). - Client options:
compression(alias forcompress),query_limit, timeouts, and more. - HTTP/TLS options: options for the HTTP pool and TLS (for example,
ch_http_max_field_name_size=99999,ca_cert=certifi).
Core queries
The dialect supports SQLAlchemy CoreSELECT queries with joins, filters, ordering, limits/offsets, and DISTINCT.
DELETE with a required WHERE clause is supported:
DDL and reflection
You can create databases and tables using the provided DDL helpers and type/engine constructs. Table reflection (including column types and engine) is supported.clickhousedb_default_type, clickhousedb_codec_expression, and clickhousedb_ttl_expression when present on the server.
Inserts (Core and basic ORM)
Inserts work via SQLAlchemy Core as well as with simple ORM models for convenience.Scope and limitations
- Core focus: Enable SQLAlchemy Core features like
SELECTwithJOINs (INNER,LEFT OUTER,FULL OUTER,CROSS),WHERE,ORDER BY,LIMIT/OFFSET, andDISTINCT. DELETEwithWHEREonly: The dialect supports lightweightDELETEbut requires an explicitWHEREclause to avoid accidental full-table deletes. To clear a table, useTRUNCATE TABLE.- No
UPDATE: ClickHouse is append-optimized. The dialect doesn’t implementUPDATE. If you need to change data, apply transformations upstream and re-insert, or use explicit text SQL (for example,ALTER TABLE ... UPDATE) at your own risk. - DDL and reflection: Creating databases and tables is supported, and reflection returns column types and table engine metadata. Traditional PK/FK/index metadata isn’t present because ClickHouse doesn’t enforce those constraints.
- ORM scope: Declarative models and inserts via
Session.add(...)/bulk_save_objects(...)work for convenience. Advanced ORM features (relationship management, unit-of-work updates, cascading, eager/lazy loading semantics) aren’t supported. - Primary key semantics:
Column(..., primary_key=True)is used by SQLAlchemy for object identity only. It doesn’t create a server-side constraint in ClickHouse. DefineORDER BY(and optionalPRIMARY KEY) via table engines (for example,MergeTree(order_by=...)). - Transactions and server features: Two-phase transactions, sequences,
RETURNING, and advanced isolation levels aren’t supported.engine.begin()provides a Python context manager for grouping statements but performs no actual transaction control (commit/rollback are no-ops).
