gpt4 book ai didi

python - psycopg2 类型错误 : not all arguments converted during string formatting

转载 作者:太空狗 更新时间:2023-10-29 18:14:27 25 4
gpt4 key购买 nike

我正在尝试执行一个简单的查询,但无论我如何传递参数都会出现此错误。

这是查询(我正在使用 Trac 数据库对象连接到数据库):

cursor.execute("""SELECT name FROM "%s".customer WHERE firm_id='%s'""" % (schema, each['id']))

schema 和 each['id'] 都是简单的字符串

print("""SELECT name FROM "%s".customer WHERE firm_id='%s'""" % (schema, each['id']))

结果:SELECT name FROM "Planing".customer WHERE firm_id='135'

错误是在 firm_id= 之后删除引号,但这种方式将参数视为整数,::text 会导致完全相同的错误。

最佳答案

在我的例子中,我没有意识到您必须将一个元组传递给 cursor.execute。我有这个:

cursor.execute(query, (id))

但我需要传递一个元组来代替

cursor.execute(query, (id,))

关于python - psycopg2 类型错误 : not all arguments converted during string formatting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21524482/

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