我正在尝试从Python脚本更新postgresql db中的表,但在以下行中得到错误:
update_query='update product_'+lang+' set "StockQuantity"='+str(item[1].StockQuantity )+' where "ProductId"='+str(item[1].ProductId)
错误:
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) operator does not exist: character varying = integer
LINE 1: ... product_fr set "StockQuantity"=700 where "ProductId"=367945
^
HINT: No operator matches the given name and argument type(s). You
might need to add explicit type casts.
[SQL: 'update product_fr set "StockQuantity"=700 where
"ProductId"=367945'] (Background on this error at:
http://sqlalche.me/e/f405)
我认为问题出在更新查询中我的ProductId值;我将其转换为字符串,但无法正常工作。
谁能帮我解决这个问题?
示例查询在postgresql中运行:
无法运作的查询-
update public.product_fr set "StockQuantity"=1900 where "ProductId"=367945
工作查询
update public.product_fr set "StockQuantity"=1900 where "ProductId"='367945'
您的ProductId可能是文本类型,因此您需要将数字换成引号,所以它也是文本类型。
update_query='update product_'+lang
+' set "StockQuantity"='+str(item[1].StockQuantity )
+' where "ProductId"=\''
+str(item[1].ProductId) + '\''
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句