首页 > 解决方案 > Panda.run_sql_query for where .. in .. 结构?

问题描述

我有一个结构为 where a in b kind 的 sql 查询。我正在尝试使用 run_sql_query 通过 pandas 运行它以获取数据帧。但似乎没有数据结构适用于熊猫查询。我应该有什么让它工作?

sql:

Select * from Table where a in (:input)

Python:

conn = cx-oracle.connect(....)

df = pd.run_sql_query(sql,conn, params= {'input':('A','B')})

错误信息:

cx_Oracle.NotSupportedError: Python value of type tuple not supported.

我尝试了 numpy 数组和列表,但似乎没有一个工作。这里应该使用什么数据结构?

标签: pythonsqlpandascx-oracle

解决方案


尝试这个:

myinput = ('a','b','c')
myinput = str(myinput)
#Now your query will end up like
# select * from tablename where value in ('a','b','c')
df = pd.run_sql_query(sql,conn, params= {'input':myinput})

推荐阅读