python中写SQL语句里面的变量如何优雅替换查询,不至于写大量冗余的代码

时间:2022-12-09 09:57:23


导库

import pandas as pd
from pigeon.connector import new_clickhouse_connector
from pigeon.connector import new_impala_connector

ch_conn = new_clickhouse_connector()
impa_conn = new_impala_connector()
hhh_sql ="""
select ID,1,2,3
from table
where time ='{}'
"""
pd.read_sql(hhh_sql.format('今天的时间'),ch_conn)

手动输出成功

学习必须与实干相结合。—— 泰戈尔