? at the interactive prompt.
The assistant is an agent: rather than generating one query blindly, it works towards the answer step by step with the help of the following tools:
list_databases- list the databases of the serverlist_tables- list the tables of a databaseshow_create_table- read theCREATE TABLEstatement of a tableconsult_documentation- look an entity up in the embedded documentation (thesystem.documentationtable)read_query_log- read your earlier queries fromsystem.user_query_logrun_readonly_query- run a read-only query without asking, under a sandbox (readonly = 1, a 30-second and a 10 GiB limit)run_query- run any other query, after you confirm it
Prerequisites
The assistant needs a model provider. The quickest way is an Anthropic or OpenAI key in an environment variable:aiGenerate function of the server you are connected to. This takes two things on the server: default credentials configured for AI functions (the ai_function_text_default_credentials setting), and AI functions not being disabled (the allow_ai_functions setting, which is on by default). Without the credentials the assistant is not available - see providers.
Connecting to the ClickHouse SQL playground
We’re going to explore this feature using the ClickHouse SQL playground. We can connect to the ClickHouse SQL playground using the following command:We’ll assume you have ClickHouse installed, but if not, refer to the installation guide
Asking ClickHouse questions in natural language
Now it’s time to start asking some questions!Finding expensive housing markets
Let’s start by asking a question about house prices. The SQL playground contains a UK house prices dataset, which the assistant discovers on its own:- Schema discovery - it explored the databases and the tables of the relevant one
- Table analysis - it read the structure of the
uk_price_paidtable - Query execution - it ran a query built from your question and the schema it discovered. The query only reads an ordinary table, so it ran as a read-only query without asking, and its result is displayed as if you had typed it
- Answer - it read the result and answered the question
Asking follow-up questions
The conversation keeps its context between questions in the same session, so a follow-up does not have to repeat what was already said, and the assistant does not have to discover the schema again:? clear.
Queries that change data
The assistant runs only read-only queries on its own. Anything else - writes, DDL,SET, or a read that can reach outside of the server, such as a table function or a table of an external engine - is shown at the prompt first, and runs only after you confirm it. The one exception is reading the schema: for a table of a database backed by an external system (MySQL, PostgreSQL, a data-lake catalog), the assistant fetches the definition of the table from that system without asking. It reads metadata only, and the credentials in it are masked - see security. The confirmation looks like this:
demo user is read-only, so such queries fail there even when confirmed.