list_databases- List all available databases in the ClickHouse instancelist_tables_in_database- List all tables in a specific databaseget_schema_for_table- Get theCREATE TABLEstatement (schema) for a specific table
Prerequisites
We’ll need to add an Anthropic or OpenAI key as an environment variable: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! The text to SQL feature is effectively a one-shot query generation tool. Since it doesn’t maintain conversation history, include as much useful context as possible in your question. Be specific about: Time periods or date ranges The type of analysis you want (averages, totals, rankings, etc.) Any filtering criteriaFinding expensive housing markets
Let’s start by asking a question about house prices. The SQL playground contains a UK house prices dataset, which the AI will automatically discover:- Schema discovery - Explores available databases and tables
- Table analysis - Examines the structure of relevant tables
- Query generation - Creates SQL based on your question and the discovered schema
uk_price_paid table and generated a query for us to run.
If we run that query, we’ll see the following output: