输入:20210519
解析后:2021-05-19
因为clickhouse里面toDate( ) 括号里是2021-05-19 这种类型
# -*- coding: utf-8 -*-
from clickhouse_driver import Client
import datetime
## --数据库连接函数,创建表
client = Client(host='10.37.22.29',
database='zxba',
port='8000',
user='root',
password='123456'
)
date_str = '20210326'
v_date = date_str[0:4] + '-' + date_str[4:6] + '-' + date_str[6:8]
sql_concat = " select * from zxba.table" + " where etl_date = toDate('" + v_date + "') limit 2"
sql_result = client.execute(sql_concat)
print(sql_result)
结果: