02 Create the table
One CREATE TABLE for 26.5M forex ticks, and why base and quote lead the sort key — the decision you will feel in module 04.
First create an empty table to hold the forex ticks. Open the SQL Console, paste the statement below, and run it.
-- 26.5M forex ticks (12 pairs incl. gold, Jan 2020); base+quote+time lead the sort key
CREATE TABLE forex
(
datetime DateTime64(3, 'UTC'), -- millisecond quote timestamp
bid Float64,
ask Float64,
base LowCardinality(String), -- e.g. 'EUR', 'XAU' (gold)
quote LowCardinality(String), -- e.g. 'USD', 'JPY'
pair String ALIAS concat(base, '/', quote), -- handy label, computed on read
spread Float64 ALIAS ask - bid, -- bid/ask spread
mid Float64 ALIAS (bid + ask) / 2 -- mid price
)
ENGINE = MergeTree
ORDER BY (base, quote, datetime);Why this shape? base and quote lead the ORDER BY — the table's sort key. That means
filtering by a currency pair, and a time range, lets ClickHouse skip almost all the data. You'll
see exactly how much that matters in
the last query of module 04.
You should see
Ok. — the table is created and empty. Next you'll fill it.
01 Sign in to ClickHouse Cloud
Create a free ClickHouse Cloud service and open the SQL Console — about five minutes, and the only prerequisite for everything that follows.
03 Load the data — two ways
The same 26.5M ticks loaded twice: ClickPipes, the managed pipeline you would use in production, then the s3() one-liner — and when to reach for which.