-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Quote table names in to_sql #13206
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
@the4thv that's indeed probably a good fix, however, note that the usage of the |
I can getting it working with sqlalchemy, thanks. 👍 |
@the4thv I will leave this issue open as it is probably a problem for sqlite as well (and the support for this flavor without using sqlalchemy is to stay, only mysql will be removed) PR with the fix is always welcome! |
@jorisvandenbossche, I will give it a go at lunchtime. |
It looks like this issue is already fixed and good to close. Line 1322 in 34bd15d
|
I don't think the proposed change in the top post is implemented. But in any case, best to add a test for this to check that it is actually solved. Do you have a small reproducible example that shows it is working? PRs always welcome to add a test case! |
* Add test for bug #13206. * Improve test by reading back the values from sql and comparing. Also fixes coding style violation.
I've added a test case in the PR referenced above that has now been merged. Was there anything else to do in order to close this issue? |
I believe so. @jorisvandenbossche does that sound right? table names are quoted for sqlite, and everyone else should be using a sqlalchemy engine? |
Yes! |
* Add test for bug pandas-dev#13206. * Improve test by reading back the values from sql and comparing. Also fixes coding style violation.
* Add test for bug pandas-dev#13206. * Improve test by reading back the values from sql and comparing. Also fixes coding style violation.
This bug fix actually introduced a new bug for those of us using pandas with Netezza and jaydebeapi (which is treated like sqlite). What happens is that Netezza treats quotes as literal and injects these quotes into the table name, which then prevents other parts of the code from functioning properly. EDIT: I found that if ALLCAPS are used for table names, it works fine even for Netezza and jaydebeapi. |
Expected Output
(no output, just successful write to db table)
output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.4.3.final.0
python-bits: 32
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
pandas: 0.18.1
nose: None
pip: 8.1.2
setuptools: 18.0.1
Cython: None
numpy: 1.11.0
scipy: None
statsmodels: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.4.2
pytz: 2015.4
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: 0.9.3
xlwt: 0.8.0
xlsxwriter: 0.7.3
lxml: None
bs4: 4.4.0
html5lib: 0.999999
httplib2: 0.9.2
apiclient: 1.5.0
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
boto: 2.38.0
pandas_datareader: None
Proposed fix:
Line 1478 of pandas\io\sql.py, wrapping the escape(self.name) with ``:
create_stmts = ["CREATE TABLE
" + escape(self.name) + "
(\n" +',\n '.join(create_tbl_stmts) + "\n)"]
The text was updated successfully, but these errors were encountered: