Postgresql psycopg2 : 'list'对象没有属性'replace'



我有一个简单的DB数据操作例程,抛出' updateBestandInDB错误'列表'对象没有属性'replace';这对我来说是个谜。

def updateBestandInDB(conn,bestandID,free,used,total):
sql = 'UPDATE "Bestand" SET "free" = %s, "used" = %s, "total" = %s, "time" = %s WHERE "id" = %s;'
retVal = False
try:
curs = conn.cursor()
curs.execute(sql,(free,used,total,datetime.now(),uuid.UUID(bestandID)))
# get the modified id back
#bestand_id = curs.fetchone()[0]
#print('Return from updateBestandInDB :', bestand_id)
# commit the changes to the database
conn.commit()
retVal = True
except (Exception, psycopg2.DatabaseError) as error:
print("updateBestandInDB Error")
print(error)
finally:
# close communication with the database
curs.close()
return retVal

使用的参数都不是列表。Free, used和total是浮动的。谢谢你的评论。

我已经搜索了stackoverflow和谷歌,但没有一个解决方案似乎总是适合列表,这不是这里的情况-至少对我来说是不可见的。

所以做一件事让你自己清楚,你的意思是自由,使用和总数是浮动。好吧,随它去吧,那么最好是直接赋值如('1234'或1234),字符串或int,但只有一个元素。如果它运行良好的手段,那么显然错误将只在最佳状态。为了进一步澄清,请输入bestdid值,如['1234'],然后您肯定会理解错误。希望这对你有帮助。

相关内容

最新更新