-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
to_sql double quoting in create index #9393
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
Here is the patch I am now using in my monkey patch and works fine: if len(ix_cols):
cnames = "_".join(ix_cols)
cnames_br = ",".join([br_l + c + br_r for c in ix_cols])
idx_name = quote_identifier("ix_{tbl}_{cnames}".format(
tbl=self.name, cnames=cnames
))
create_stmts.append(
"CREATE INDEX {idx_name} ON {tbl} ({cnames_br})".format(
idx_name=idx_name, tbl=self.name, cnames_br=cnames_br)) I will be glad to submit proper PR, but wanted to know if you think it might make even more sense to apply the quote automatically so that one does not have to quote table name beforehand and call |
This does indeed looks like a bug. But, for the record:
cc @artemyk |
This is sqlite3. This is a simple test case btw: import pandas as pd
import sqlite3 as db
from pandas.io import sql as pd_sql
dbname = '/home/dashesy/test.sqlite'
con = db.connect(dbname)
df = pd.DataFrame(np.ones(3))
pd_sql.to_sql(df, '_b.m_go_test_01-30', con, if_exists='replace')
pd_sql.to_sql(df, quote_identifier('_b.m2_go_test_01-30'), con, if_exists='replace') I think this would be still an issue if one has a table created in 0.14 and wants to access it in the fixed 0.15 and still quotes the table name, but this is a little too stretched. |
@dashesy Thanks for testing! We can add your test case (or if you want to do that in a PR, certainly welcome!) |
For PR I did not find something related so added a new module. This is my first PR here, so please let me know if I need to revise for coding style or anything. |
@dashesy I pointed you to the correct place for sql tests About the docs, you can certainly add somewhere a note that table names do not have to be quoted |
@jorisvandenbossche did you mean to close this? (as the PR is still open/not merged) |
ah no, that button .. |
I think this one is the right place, I get many errors on |
Great to hear that #8986 fixed this pre-emptively ;-) Yes, you can have table names with quotes since those appear to be legal identifier names in sqlite. |
I have table names that include
_
,.
and-
, up until Pandas .14 I used to quote the table name like this:then call:
But since 0.15 if I do not quote
CREATE TABLE
(orDROP TABLE
) will give me an error:And if I do quote
CREATE INDEX
will give me an error:The problem is that in
CREATE INDEX ix_{tbl}_{cnames} ON {tbl} ({cnames_br})
CREATE INDEX thinks it is the only one trying to prepend a namespace with_
and thus does not check if{tbl}
is already quoted.The proper fix should do what
quote_identifier
does with"
and escape them, or just usequote_identifier
and then prependix_
.This is the query that it tries and gives error:
The text was updated successfully, but these errors were encountered: