I want to insert data without duplicates. Triplet of these fields should be unique ticker, kline_type, dateTime
Found out that i should use ReplacingMergeTree https://clickhouse.com/docs/ru/engines/table-engines/mergetree-family/replacingmergetree/
I am trying to
import clickhouse_driver
def prepare_table():
client = clickhouse_driver.Client.from_url(f'clickhouse://default:{os.getenv("CLICK_PASSWORD")}@localhost:9000/crypto_exchange')
# field names from binance API
client.execute('''
CREATE TABLE IF NOT EXISTS historical_data_binance
(
dateTime DateTime,
closeTime Int64,
open Float64,
high Float64,
low Float64,
close Float64,
volume Float64,
kline_type String,
ticker String
) ENGINE = ReplacingMergeTree
ORDER BY (ticker, kline_type, dateTime)
''')
return client
prepare_table()
But I think that my solution didn't work, because I see duplicates:
2021-11-04 11:00:00 │ 1636027199999 │ 61894.82 │ 62188.78 │ 60866.46 │ 61444.74 │ 20.158382 │ 1h │ BTCUSDT │
│ 2021-11-04 12:00:00 │ 1636030799999 │ 61420.86 │ 61698.74 │ 58754.41 │ 61621.01 │ 15.721483 │ 1h │ BTCUSDT │
└─────────────────────┴───────────────┴──────────┴───────────┴──────────┴──────────┴───────────┴────────────┴─────────┘
┌────────────dateTime─┬─────closeTime─┬─────open─┬─────high─┬──────low─┬────close─┬────volume─┬─kline_type─┬─ticker──┐
│ 2021-11-04 11:00:00 │ 1636027199999 │ 61894.82 │ 62188.78 │ 60866.46 │ 61444.74 │ 20.158382 │ 1h │ BTCUSDT
What is the proper way to insert data?