无法解析 DateTime 类型的表达式
Cannot parse expression of type DateTime
如有错误请在评论中指正
我正在尝试将测试数据插入 clickhouse。出于测试目的,我使用 datetime.now(100% 正确的日期时间)
在我的代码的最后一行我有一个错误:
clickhouse_driver.errors.ServerException: Code: 62.
DB::Exception: Cannot parse expression of type DateTime here: 2021-11-01 00:19:12.933220, 2021-11-01 00:19:12.933237, 1,2,3,4,5, "TYPE_K", "BTCUSDT");
. Stack trace:
我该如何解决?
from clickhouse_driver import Client
import os
from datetime import datetime
client = Client.from_url(f'clickhouse://default:{os.getenv("CLICK_PASSWORD")}@localhost:9000/crypto_exchange')
print(client.execute('SHOW TABLES'))
# field names from binance API
client.execute('''
CREATE TABLE IF NOT EXISTS historical_data_binance
(
dateTime DateTime,
closeTime DateTime,
open Float64,
high Float64,
low Float64,
close Float64,
volume Float64,
kline_type String,
ticker String
) ENGINE = Memory
''')
client.execute(f'''
INSERT INTO crypto_exchange.historical_data_binance (*) VALUES
({datetime.now()}, {datetime.now()}, 1,2,3,4,5, "TYPE_K", "BTCUSDT");
''')
我的解决方案
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 = Memory
''')
return client
def insert_data(client, insert_data, db_name="crypto_exchange", table_name="historical_data_binance"):
"""
insert_data = {
"dateTime": dateTime,
"closeTime": closeTime,
"open": open,
"high": hign,
"low": low,
"close": close,
"volume": volume,
"kline_type": kline_type,
"ticker": ticker
}
"""
columns = ', '.join(insert_data.keys())
query = 'insert into {}.{} ({}) values'.format(db_name, table_name, columns)
data = []
data.append(insert_data)
client.execute(query, data)
如有错误请在评论中指正
我正在尝试将测试数据插入 clickhouse。出于测试目的,我使用 datetime.now(100% 正确的日期时间)
在我的代码的最后一行我有一个错误:
clickhouse_driver.errors.ServerException: Code: 62.
DB::Exception: Cannot parse expression of type DateTime here: 2021-11-01 00:19:12.933220, 2021-11-01 00:19:12.933237, 1,2,3,4,5, "TYPE_K", "BTCUSDT");
. Stack trace:
我该如何解决?
from clickhouse_driver import Client
import os
from datetime import datetime
client = Client.from_url(f'clickhouse://default:{os.getenv("CLICK_PASSWORD")}@localhost:9000/crypto_exchange')
print(client.execute('SHOW TABLES'))
# field names from binance API
client.execute('''
CREATE TABLE IF NOT EXISTS historical_data_binance
(
dateTime DateTime,
closeTime DateTime,
open Float64,
high Float64,
low Float64,
close Float64,
volume Float64,
kline_type String,
ticker String
) ENGINE = Memory
''')
client.execute(f'''
INSERT INTO crypto_exchange.historical_data_binance (*) VALUES
({datetime.now()}, {datetime.now()}, 1,2,3,4,5, "TYPE_K", "BTCUSDT");
''')
我的解决方案
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 = Memory
''')
return client
def insert_data(client, insert_data, db_name="crypto_exchange", table_name="historical_data_binance"):
"""
insert_data = {
"dateTime": dateTime,
"closeTime": closeTime,
"open": open,
"high": hign,
"low": low,
"close": close,
"volume": volume,
"kline_type": kline_type,
"ticker": ticker
}
"""
columns = ', '.join(insert_data.keys())
query = 'insert into {}.{} ({}) values'.format(db_name, table_name, columns)
data = []
data.append(insert_data)
client.execute(query, data)