petl.todb not work DELETE SQL syntax error
yqz945 opened this issue · 2 comments
yqz945 commented
Minimal, reproducible code sample, a copy-pastable example if possible
## with sqlalchemy session
tt = [['foo', 'bar'],
['a', 1],
['b', 2],
['c', 2]]
petl.todb(
tt,
Session(create_engine(config.SQLALCHEMY_DATABASE_URI)),
tablename='tyedu_fct_ac_homework',
create=True
)
## pymysql.connect
tt = [['foo', 'bar'],
['a', 1],
['b', 2],
['c', 2]]
petl.todb(
tt,
pymysql.connect(**self.params['destination']['conn_params']),
tablename='tyedu_fct_ac_homework',
create=True
)
Problem description
The two got the same error:
sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError) (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"tyedu_fct_ac_homework"' at line 1')
[SQL: DELETE FROM "tyedu_fct_ac_homework"]
First I use clickhouse, got the error, then, I change to mysql, the error is still.
Version and installation information
- Value of
petl.__version__
1.7.11 and 1.7.8 - Version information for any third-party package dependencies that are relevant
- Version of Python interpreter python 3.10
- Operating system (Linux/Windows/Mac) : win11
- How petl was installed (e.g., "using pip into virtual environment", or "using conda") pycharm with venv
bluechanel commented
N.B., for MySQL the statement SET SQL_MODE=ANSI_QUOTES is required to ensure MySQL uses SQL-92 standard quote characters.
>>> import pymysql
>>> connection = pymysql.connect(password='moonpie', database='thangs')
>>> # tell MySQL to use standard quote character
... connection.cursor().execute('SET SQL_MODE=ANSI_QUOTES')
>>> # load data, assuming table "foobar" already exists in the database
... etl.todb(table, connection, 'foobar')
yqz945 commented
@bluechanel Thank you very much. It's right. I didn't notice the SET statement.