Skip to main content
Skip to main content
Edit this page

Using a clickhouse-local database

clickhouse-local is a CLI with an embedded version of ClickHouse. It gives users the power of ClickHouse without having to install a server. In this guide, we will learn how to use a clickhouse-local database from chDB.

Setup

Let's first create a virtual environment:

And now we'll install chDB. Make sure you have version 2.0.2 or higher:

And now we're going to install ipython:

We're going to use ipython to run the commands in the rest of the guide, which you can launch by running:

Installing clickhouse-local

Downloading and installing clickhouse-local is the same as downloading and installing ClickHouse. We can do this by running the following command:

To launch clickhouse-local with the data being persisted to a directory, we need to pass in a --path:

Ingesting data into clickhouse-local

The default database only stores data in memory, so we'll need to create a named database to make sure any data we ingest is persisted to disk.

Let's create a table and insert some random numbers:

Let's write a query to see what data we've got:

Once you've done that, make sure you exit; from the CLI as only one process can hold a lock on this directory. If we don't do that, we'll get the following error when we try to connect to the database from chDB:

Connecting to a clickhouse-local database

Go back to the ipython shell and import the session module from chDB:

Initialize a session pointing to demo..chdb:

We can then run the same query that returns the quantiles of numbers:

We can also insert data into this database from chDB:

We can then re-run the quantiles query from chDB or clickhouse-local.