[英]How to add escape with in python “”" quote string?
i am trying to integrate my AWS lambda function to query my postgresql.我正在尝试集成我的 AWS lambda function 来查询我的 postgresql。
sql_update_query = """update "YP_SUPPLIERS" set %s =%s where "YP_SUPPLIERS"."supplierID"= %s"""
cursor.execute(sql_update_query, (key[0],value[0],supplierID))
Apparently while creating the table "" where used.显然在创建使用的表“”时。 This is pretty hectic to work around this.
解决这个问题非常忙碌。
error错误
syntax error at or near "'supplierName'"
LINE 1: update "YP_SUPPLIERS" set 'supplierName'='key' where "YP_SU...
it seems set %s who's value is supplierName should be with in "".似乎设置 %s 的值是供应商名称应该在“”中。 Can any one let me know a work around or how can i implement this properly please
任何人都可以让我知道解决方法或我该如何正确实施
Use the SQL composition feature of psycopg2使用 psycopg2 的SQL 组合功能
from psycopg2 import sql
sql_update_query = sql.SQL(
"""update "YP_SUPPLIERS"
set {} = %s,
{} = %s
where "YP_SUPPLIERS"."supplierID" = %s""").format(
sql.Identifier(key[0]),
sql.Identifier(key[1])
)
cursor.execute(sql_update_query, (value[0], value[1], supplierID))
Use this用这个
sql_update_query = """update YP_SUPPLIERS set %s =%s where supplierID= %s"""
cursor.execute(sql_update_query%(key[0],value[0],supplierID))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.