NAME DBD::ClickHouse - DBI driver for ClickHouse over HTTP SYNOPSIS use DBI; my $dbh = DBI->connect( 'dbi:ClickHouse:database=default;host=localhost;port=8123', $user, $password, { RaiseError => 1, PrintError => 0 }, ); my $rows = $dbh->selectall_arrayref( 'SELECT city, temp_c FROM observations WHERE day = ?', { Slice => {} }, '2026-01-15', ); my $sth = $dbh->prepare('INSERT INTO observations (city, temp_c) VALUES (?, ?)'); $sth->execute('Seattle', 11.5); $dbh->disconnect; DESCRIPTION AI disclosure: this module was written with AI assistance. The maintainer, Mike Schienle, reviewed, tested, and released it. See AI_POLICY.md in the distribution. The maintainer uses DBD::ClickHouse in production, in his own weather-data processing pipelines. DBD::ClickHouse is a pure-Perl DBI driver for ClickHouse. It speaks the ClickHouse HTTP interface (port 8123, or 8443 with TLS) and is intended for queries, DDL, metadata, and small or medium inserts. It is the library equivalent of the "clickhouse-client" invocations many scripts shell out to. Bulk loading through an external pipe or "clickhouse-client" CSV stream is not this driver's job. "clickhouse_insert" and "execute_array" cover multi-row inserts that still fit in a request. The driver targets Perl 5.16 or newer and ClickHouse servers that provide "TabSeparatedWithNamesAndTypes", "RowBinaryWithNamesAndTypes" and "JSONCompactEachRowWithNamesAndTypes" (current 23.x through 26.x releases). Version 0.11 was tested against ClickHouse 26.10.2.103. REQUIREMENTS * Perl 5.16 or newer * DBI 1.643 or newer * Core modules at runtime: JSON::PP, Encode, IO::Socket::INET, IO::Compress::Gzip, Compress::Raw::Zlib * Cpanel::JSON::XS 4 or JSON::XS 4, recommended. Result rows are decoded with the first of those that loads, and with JSON::PP otherwise. The pure-Perl decoder is fine for short queries and much too slow for large streams. * IO::Socket::SSL 2.0 or newer when the DSN sets "ssl=1" * A ClickHouse HTTP endpoint DBI itself is XS and needs a compiler. DBD::ClickHouse does not. The JSON modules above are optional and, on a Mac, "cpanm Cpanel::JSON::XS" is the one to install if large selects matter. LIMITATIONS * No transactions, no savepoints, no "last_insert_id", no multi-statement text, no server-side cursor beyond streaming the HTTP body. * "prepare" does not round-trip to the server, so a bad table name is reported at "execute". * Streaming "rows" is -1 until the last row has been fetched. The summary on a streaming response can be incomplete because the driver does not set "wait_end_of_query" for that mode. * A streamed "clickhouse_insert" larger than the server's "max_insert_block_size" (about 1M rows by default) may commit earlier blocks before a later row fails to parse. Use "clickhouse_insert_rows_per_request" or "insert_format=legacy" if you need smaller units of failure, and "insert_deduplication_token" or a staging table if you need all-or-nothing. * "rowbinary" does not decode Int128/Int256/UInt128/UInt256, Decimal wider than 18 digits, IPv6, or composite types; those results are re-run as "tsv" or "json" (one extra round trip per statement handle). * A streaming statement holds the connection. * RowBinary decoding of 64-bit integers (Int64, UInt64, DateTime64, Decimal64) needs a perl with 64-bit integers, and RowBinary decoding of "DateTime"/"DateTime64" in a non-UTC zone needs "POSIX::tzset" (not available on Windows) and, for named zones such as "America/Chicago", the system zoneinfo database. When one of these is missing, the statement is re-run as "tsv" (or "json"), where the server formats the values, so results stay correct at the cost of one extra round trip. POSIX TZ rule strings (for example "CST6CDT,M3.2.0,M11.1.0") are accepted as zone names and need no zoneinfo database. * "execute_array" chunks are durable as soon as each request succeeds. * Binary "String" values that are not UTF-8 are not preserved by "json"; ClickHouse's JSON output replaces them. "tsv" and "rowbinary" return them as byte strings. * "Float32" is recovered by snapping the decimal JSON number, not by reading the original bits. Values that survive "toFloat32" match; a number that was not a binary32 to begin with is the nearest binary32. * Decimals and integers wider than the native Perl integer are strings. * Server-side parameters are limited to about 32KiB in the URL, then the driver switches to client substitution for that call. * One HTTP session runs one statement at a time. Do not share a connected handle across ithreads. After "fork", call "clickhouse_reset_connection" in the child before the next query. * "primary_key_info" is the MergeTree key, not a uniqueness constraint. INSTALLATION On a Mac, Homebrew Perl is the practical interpreter. The system Perl is often missing or older than 5.16. brew install perl brew install cpanminus # or: curl -L https://cpanmin.us | perl - App::cpanminus cpanm DBI Cpanel::JSON::XS cpanm DBD::ClickHouse From a checkout of this distribution: perl Makefile.PL make make test make install # or cpanm . "cpanm DBI" compiles DBI, so the Xcode command-line tools need to be present. Installing DBD::ClickHouse after that is pure Perl. For TLS: cpanm IO::Socket::SSL TESTING Unit tests always run. Live tests run only when a server is reachable: export DBD_CLICKHOUSE_TEST_DSN='dbi:ClickHouse:database=default;host=127.0.0.1;port=8123' export DBD_CLICKHOUSE_TEST_USER=default export DBD_CLICKHOUSE_TEST_PASSWORD=... # or: export DBD_CLICKHOUSE_TEST_CLIENT_CONFIG=1 (~/.clickhouse-client/config.xml) prove -lr t Without "DBD_CLICKHOUSE_TEST_DSN" the live scripts skip. They create scratch tables named ".__