python - 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
解决方案
推荐阅读
- apache-spark - 压缩宽拼花文件直接缓冲内存错误(拼花对宽表的适用性)
- sql - 数据库查询在批处理文件中不起作用
- go - 在 golang 中,移动打开的文件会导致泄漏或任何其他问题吗?
- reflection - Kotlin:获取方法参数值
- java - 如何在没有语法错误的情况下在 main 中显示支持文件的输出?
- tableau-api - 如何使用 Tableau Desktop 自动构建和保存图形?
- r - 按月和年连续观察
- postgresql - Postgres 数据库文件如何更新?
- linux - 如何找到单词在字符串中的位置?
- json - 使用python将CSV数据导入MongoDB