【发布时间】:2022-01-01 07:42:43
【问题描述】:
我正在尝试在 Python 中使用 prestodb 并在查询中将数字列表作为参数传递,它给出了这个错误:
PrestoUserError: PrestoUserError(type=USER_ERROR, name=TYPE_MISMATCH, message="line 208:33: IN value and list items must be the same type: bigint", query_id=20211122_175131_24052_rruhu)
代码类似这样:
import prestodb
from prestodb import dbapi
import os
conn=prestodb.dbapi.connect(
host=os.environ['aa'],
port=os.environ['bb'],
user=os.environ['cc'],
password=os.environ['dd'],
catalog='hive'
)
date_start = '2021-10-10'
date_end = '2021-10-15'
list_id = (1,2,3,4)
sql = '''
SELECT
*
FROM
table
WHERE
DATE BETWEEN '{date_start}'
AND '{date_end}'
AND ID in ({list_id})
'''.format(date_start=date_start,date_end=date_end,list_id=list_id)
cur = conn.cursor()
cur.execute(sql)
query_result = cur.fetchall()
【问题讨论】:
-
如果答案适合您,请将其标记为accepted one(答案旁边的复选标记)。