gpt4 book ai didi

python - 在单个 pyhive.execute 命令中执行多个查询

转载 作者:太空宇宙 更新时间:2023-11-03 11:15:38 25 4
gpt4 key购买 nike

使用 pyhive,是否可以执行多个 hql,例如“CREATE TABLE TABLE1 (ITEM_KEY BIGINT);CREATE TABLE TABLE2 (ITEM_NAME BIGINT);”。

示例代码

from pyhive import hive
conn = hive.Connection(host=host
, port=port, username=user
, password=passwd
, auth=auth)
cursor = conn.cursor()
query= 'CREATE TABLE TABLE1 (ITEM_KEY BIGINT );CREATE TABLE TABLE2 (ITEM_NAME BIGINT );'.
cursor.execute(query)

最佳答案

如何拆分查询并一个一个地执行它们?

qList = query.split(";")
for q in qList:
cursor.execute(q)

关于python - 在单个 pyhive.execute 命令中执行多个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52160361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com