from clickhouse_sqlalchemy import make_session from sqlalchemy import create_engine from sqlalchemy.sql import text import urllib.parse user='default' pw=urllib.parse.quote_plus('Lovedan@971220') database='default' addrs=['192.168.51.2:8123','192.168.51.3:8123'] for addr in addrs: connection = f"clickhouse://{user}:{pw}@{addr}/{database}" engine= create_engine(connection,pool_size=100,pool_recycle=3600,pool_timeout=10) clickhouse_cursor = make_session(engine=engine) sql='show tables;' query_result = clickhouse_cursor.execute(text(clickhouse_sql_str)) try: fields = query_result._metadata.keys #字段名 print(fields._keys) for item in query_result.fetchall(): #具体内容 print(item) finally: query_result.close() clickhouse_cursor.close()
标签:engine,sqlalchemy,python,数据库,result,import,query,clickhouse From: https://www.cnblogs.com/love-DanDan/p/18085234