我正在尝试使用 sqlalchemy 执行以下查询。
engine=sqlalchemy.create_engine('mysql+pymysql://root:root@localhost:3306/cst')
cst_delete_query = rf"""delete from customer where STATUS like '%CT%'"""
with engine.connect().execution_options(autocommit=True) as conn:
conn.execute(cst_delete_query)
这会导致以下错误:
ValueError: unsupported format character 'C' (0x43) at index 41
答案 0 :(得分:1)
百分比字符是一个字符串运算符,应该转义以在字符串中使用。您可以使用第二个 %
将其转义。
cst_delete_query = rf"DELETE FROM customer WHERE status LIKE '%%CT%%'"