首页 > 解决方案 > Python SQL 为单引号引发错误,例如

问题描述

我正在使用 cs.execute() 在 python 中执行查询,并且我有一堆抛出错误的类似子句。以下是查询:

cs.execute("select * from "
"production.finance.invoice_transactions a "
"inner join production.core.merchant_info b "
"WHERE  a.status IN ( 'refundSettledSuccessfully', 'returnedItem' ) "
"AND b.mid_partner_id in (%s) "
"AND a.customer_profile_id LIKE 'W_%' "
"AND a.customer_profile_id NOT LIKE '%@%' "
"AND to_date(settle_time_local) between %s and %s "
"AND to_date(b.created_at) = %s ", (id, dt1, dt2, dt1))

我在有 like 子句的行出现错误。我已经通过删除 like 子句确认了这一点,并且查询成功执行。我不确定如何解决此错误。该错误特别说明它是由于单引号引起的。下面是错误。

ValueError: unsupported format character ''' (0x27) at index 1754

标签: pythonpython-3.x

解决方案


推荐阅读