-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DataFrame to_sql fails with percentage symbol %
in column name with SQLAlchemy and PostgreSQL
#11896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, I encountered a similar issue using DataFrame.read_sql_query to read data from SQL. INSTALLED VERSIONS
------------------
commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Linux
OS-release: 3.14.32-xxxx-grs-ipv6-64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: fr_FR.UTF-8
pandas: 0.17.1
nose: 1.3.7
pip: 7.1.2
setuptools: 3.3
Cython: None
numpy: 1.10.4
scipy: 0.16.1
statsmodels: None
IPython: 4.0.1
sphinx: None
patsy: None
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: 1.0.11
pymysql: 0.6.7.None
psycopg2: None
Jinja2: None |
For me this (rather old) issue was due to an outdated MySQLdb. For me, simply running the following fixed the issue:
Your mileage may vary. I hope that saves someone an hour or two. |
This issue seems to still be there with PostgreSQL. Here is a code sample to test this (you'll need to provide your engine and create a schema "python_tests" or set the schema to "public" if you don't mind adding a table there). As a workaround I will obviously change "%" to "percent". It is actually probably a bad idea to have "%" in a column name anyways so I'd be fine if an error was thrown immediatly instead of pandas trying to save then failing and then only throwing the error. The reason why I'm writing this is because in my case I was working on a table with tens of thousands of rows and jupyter crashed (the % sign was causing a great amount of spam as I saw by running my script with IPython afterwards).
|
%
in column name with SQLAlchemy and MySQL%
in column name with SQLAlchemy and PostgreSQL
I encountered the same issue using pandas 1.14. |
The following call to
to_sql
fails due to the percentage (%) symbol in the column names in pandas 0.17.1.Backtrace:
Versions:
The text was updated successfully, but these errors were encountered: