ClickHouse/clickhouse-c is a minimalist header-only C client implementing the ClickHouse Native wire format over TCP. The library consists of one core header plus optional follow-up headers for TCP, compression, codecs, and I/O backends. It is designed for embedding inside PostgreSQL extensions but contains no PostgreSQL-specific code. Including clickhouse.h alone provides a pure block decoder over caller-supplied chc_io, usable for reading clickhouse-local's FORMAT Native output from a pipe without TCP, compression, or link-time dependencies beyond libc.
The quickstart demonstrates decoding a clickhouse local query without TCP or compression. A runnable end-to-end version is available in examples/minimal_decode.c. The required server setting is output_format_native_encode_types_in_binary_format = 0; without it, the server emits binary type tags and chc_block_read returns CHC_ERR_TYPE.
Integration follows a single-translation-unit model: exactly one translation unit per consumer defines the CHC_IMPLEMENTATION macro and includes headers, while other TUs include only public declarations. A stdlib malloc/realloc/free helper is available behind CHC_PROVIDE_STDLIB_ALLOC. For palloc/repalloc/pfree wiring inside PostgreSQL extensions, see pg_clickhouse or pg_stat_ch.
Headers include clickhouse.h (core), clickhouse-client.h (TCP packet loop), clickhouse-async.h (ioless client), clickhouse-compression.h (compressed frames, LZ4 & ZSTD adapters), clickhouse-posix-io.h (blocking read/write), and clickhouse-openssl.h (SSL support). Each follow-up header is independent. Testing uses test.sh with CFLAGS and LDFLAGS for configuration.
Source: Hacker News · Summarized by HeadlinesBriefing