Postgresql 使用python在postgress中传递数字where参数条件
我试图在Python中使用postgresql。该查询针对where条件中的数字字段值。结果集未获取并给出错误(“psycopg2.ProgrammingError:无要获取的结果”)。数据库中存在代理id(整型字段)大于1的记录Postgresql 使用python在postgress中传递数字where参数条件,postgresql,Postgresql,我试图在Python中使用postgresql。该查询针对where条件中的数字字段值。结果集未获取并给出错误(“psycopg2.ProgrammingError:无要获取的结果”)。数据库中存在代理id(整型字段)大于1的记录 也许可以在代码中尝试以下内容: conn=psycopg2.connect("dbname=postgres host=localhost user=user_here password=password_here port=port_num_here") sql=
也许可以在代码中尝试以下内容:
conn=psycopg2.connect("dbname=postgres host=localhost user=user_here password=password_here port=port_num_here")
sql='SELECT*from agent,其中agent\u id>%s代码>'
data = (agentid,) # A single element tuple.
然后使用
cur.execute(sql,data)
另外,我在这里不明白你想用这段代码做什么
for row in rows:``
print " ", row[9]
是否要打印行中的每一行
或仅打印行
的第8个索引
rows = cur.fetchall()
如果你想要那个索引,你可以
print rows[9]
我无法复制您的错误消息,但我认为语法已关闭。为什么不尝试用python将agentid转换为int,然后动态生成sql并传递给cur.execute()函数呢。
print rows[9]