[英]OperationalError: near ")": syntax error in sqlite
Below is my code:下面是我的代码:
# export data to sqlite
with sqlite3.connect('realtime_crypto.sqlite') as conn:
df.to_sql('data', con=conn, if_exists='append', index=False)
Below is the error showing下面是错误显示
OperationalError Traceback (most recent call last)
Input In [5], in <cell line: 218>()
232 # export data to sqlite
233 with sqlite3.connect('realtime_crypto.sqlite') as conn:
--> 234 df.to_sql('data', con=conn, if_exists='append', index=False)
OperationalError: near ")": syntax error
I tried changing the format still not working.我尝试更改格式仍然无效。
Most probably you have single quotes in your dataframe.您的数据框中很可能有单引号。
I would recommend to use pyathena.pandas.util.to_sql
function so if the value contains single quotes, it will be automatically escaped:我建议使用pyathena.pandas.util.to_sql
函数,这样如果值包含单引号,它将自动转义:
import pandas as pd
from pyathena.pandas.util import to_sql
df = pd.DataFrame({"a": ["foo", "bar", "jim o'rourke"]})
to_sql(df, "test", conn)
How do I convert a string into safe SQL String? 如何将字符串转换为安全的 SQL 字符串?
https://github.com/laughingman7743/PyAthena/issues/238 https://github.com/laughingman7743/PyAthena/issues/238
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.