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.

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 "<db>.<prefix>_<pid>_<time>_<n>" and drop them at the
  end or on INT/TERM; they never touch any other table.
  "DBD_CLICKHOUSE_TEST_DB" selects the database (otherwise the DSN
  "database=" key, or "default"). "DBD_CLICKHOUSE_TEST_PREFIX" sets the
  table-name prefix (default "DBD_CH_Test"). "DBD_CLICKHOUSE_JSON" may be
  "PP", "XS", or "Cpanel" to force a decoder. An unknown or missing choice
  falls back to JSON::PP.

AUTHOR
  Mike Schienle <mschienle@cpan.org> (PAUSE ID MSCHIENLE).

COPYRIGHT AND LICENSE
  Copyright (C) 2026 by Mike Schienle

  This is free software; you can redistribute it and/or modify it under the
  same terms as the Perl 5 programming language system itself.

SEE ALSO
  DBI, DBD::MariaDB, the ClickHouse HTTP interface documentation.

