Search Shortcut cmd + k | ctrl + k
clickhouse_scanner

Read and write ClickHouse tables directly from DuckDB.

Maintainer(s): redox

Compatibility Matrix

This table covers all DuckDB releases that have not reached end-of-life, including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.

Platform 1.4.4 1.4.5 1.5.5 1.5.6
Linux AMD64
Linux ARM64
macOS AMD64
macOS ARM64
Windows AMD64
Windows ARM64
WebAssembly

Installing and Loading

INSTALL clickhouse_scanner FROM community;
LOAD clickhouse_scanner;

Example

INSTALL clickhouse_scanner FROM community;
LOAD clickhouse_scanner;

CREATE SECRET ch (
    TYPE clickhouse,
    HOST 'abc123.eu-west-1.aws.clickhouse.cloud',
    PORT 9440,
    USER 'default',
    PASSWORD 'my-pass',
    DATABASE 'analytics'
);
ATTACH '' AS ch (TYPE clickhouse, SECRET ch);

SELECT event, count(*)
FROM ch.analytics.events
WHERE ts > now() - INTERVAL 1 DAY
GROUP BY ALL;

INSERT INTO ch.analytics.events
SELECT * FROM read_parquet('events/*.parquet');

About clickhouse_scanner

The ClickHouse extension attaches a ClickHouse server, or ClickHouse Cloud, as a DuckDB database. Tables are read and written with ordinary DuckDB SQL over ClickHouse's native protocol, with TLS. Filters, projections and LIMITs are pushed down to ClickHouse.

Features include:

  • ATTACH support for ClickHouse databases, including secrets for credentials
  • reads from attached schemas and tables, including joins with local data
  • writes with INSERT, COPY, CREATE TABLE, UPDATE and DELETE
  • clickhouse_query and clickhouse_execute for ClickHouse SQL that DuckDB cannot express
  • clickhouse_scan to read one table without attaching a database

Added Functions

function_name function_type description comment examples
clickhouse_clear_cache table NULL NULL  
clickhouse_client_version scalar NULL NULL  
clickhouse_execute table NULL NULL  
clickhouse_query table NULL NULL  
clickhouse_scan table NULL NULL  
clickhouse_type_mapping table NULL NULL  

Overloaded Functions

This extension does not add any function overloads.

Added Types

This extension does not add any types.

Added Settings

name description input_type scope aliases
ch_connect_timeout_ms Timeout in milliseconds for connecting to ClickHouse UBIGINT GLOBAL []
ch_debug_show_queries DEBUG SETTING: print all queries sent to ClickHouse to stdout BOOLEAN GLOBAL []
ch_default_table_engine Table engine for CREATE TABLE in attached ClickHouse databases, e.g. MergeTree or ReplicatedMergeTree('/clickhouse/tables/{shard}/{database}/{table}', '{replica}') VARCHAR GLOBAL []
ch_filter_pushdown Push filters down into the queries sent to ClickHouse BOOLEAN GLOBAL []
ch_insert_block_size Minimum rows per block sent to ClickHouse during INSERT (rounded up to whole chunks) UBIGINT GLOBAL []
ch_mutations_sync mutations_sync sent with UPDATE and ALTER COLUMN mutations: 0 = do not wait, 1 = wait on this replica, 2 = wait on all replicas UBIGINT GLOBAL []
ch_order_pushdown Push LIMIT and ORDER BY … LIMIT down into ClickHouse queries BOOLEAN GLOBAL []
ch_pool_acquire_mode What to do when the pool is exhausted: force, wait or try (new ATTACHes) VARCHAR GLOBAL []
ch_pool_idle_timeout_millis Idle pooled connections are closed after this many milliseconds (new ATTACHes) UBIGINT GLOBAL []
ch_pool_max_connections Maximum number of pooled connections per attached ClickHouse database (new ATTACHes) UBIGINT GLOBAL []
ch_pool_wait_timeout_millis How long 'wait' acquire mode waits for a free connection (new ATTACHes) UBIGINT GLOBAL []
ch_receive_timeout_ms Timeout in milliseconds for receiving data from ClickHouse UBIGINT GLOBAL []