ClickHouse CREATE TABLE Generator
Turn a plain column list into a ClickHouse CREATE TABLE statement. Choose a MergeTree-family engine, ORDER BY, PARTITION BY, TTL, cluster and index granularity.
Use the tool
Why this tool exists
ClickHouse tables are shaped by decisions you do not need in other databases: the engine, the sorting key, the partition expression and a TTL. Typing the DDL from memory is slow, and common type names from other systems, like string or timestamp, are not ClickHouse types.
List your columns one per line, as name and type, and the tool maps friendly names such as string, int64, float64 and datetime to ClickHouse types. A question mark after a type makes it Nullable. You can add DEFAULT or CODEC clauses and a comment after two dashes. Pick an engine, such as MergeTree or ReplacingMergeTree, and fill in ORDER BY, PARTITION BY and TTL. Choosing a good sorting key still depends on your queries. Nothing is uploaded.
How to use it
- Enter one column per line as name type, adding ? after the type for Nullable.
- Set the table name, such as analytics.events, and choose the engine.
- Fill in ORDER BY, PARTITION BY and TTL, or leave ORDER BY blank to use the first column.
- Copy the CREATE TABLE statement and run it in ClickHouse.
Frequently asked questions
How are types mapped?
Common names like string, int, uint32, float64, bool, date and datetime are mapped to ClickHouse types such as String, Int32, UInt32, Float64, Bool, Date and DateTime. Types it does not know are passed through unchanged.
How do I make a column nullable?
Add a question mark after the type, for example referrer string?. The generated type becomes Nullable(String). Use nullable columns sparingly, since they cost extra storage and speed.
Which engines need extra arguments?
CollapsingMergeTree needs the sign column as an engine argument. ReplacingMergeTree can take a version column, and SummingMergeTree can take columns to sum. ReplicatedMergeTree uses default Keeper paths with macros.
Does it choose a good ORDER BY for me?
No. If you leave it blank, the first column is used. The best sorting key depends on how you filter and group, so choose it deliberately.