-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Escaping odd table names in SQLite not working #926
Comments
I've started trying to dig into this myself a bit. Just for fun, I decided to install / test against a Postgres database. This appears to work correctly without escaping:
|
Apparently the issue is with the first character being a number in "14M3". It tried to save a sequence of databases with a UUID and Reports are added nicely as long as there is a letter in front:
Error as soon as there is a number in front:
Fixed by adding a letter (to verify):
|
…unction for db_insert_into that supports escaping (unlike the current DBI::dbWriteTable that was used) and using build_sql rather than paste0 within db_query_fields.
I've just made a couple of changes to src-sqlite.r which I think fix the problem. I've put in a pull request (from NikNakk/dplyr). |
…unction for db_insert_into that supports escaping (unlike the current DBI::dbWriteTable that was used) and using build_sql rather than paste0 within db_query_fields.
Keeps - Uses build_sql rather than paste0 within db_query_fields Restores - DBI::dbWriteTable (fixes have occurred upstream in RSQLite)
This is fixed in the development version of RSQLite |
This report is reproduced from this Stack Overflow question:
http://stackoverflow.com/questions/28132697/bracket-escaped-table-names-with-dplyr?noredirect=1#comment44719663_28132697
I'm programmatically fetching a bunch of datasets, many of them having silly names that begin with numbers and have special characters like minus signs in them. Because none of the datasets are particularly large, and I wanted the benefit R making its best guess about data types, I'm (ab)using dplyr to dump these tables into SQLite.
I am using square brackets to escape the horrible table names, but this doesn't seem to work. For example:
This results in the error message:
Error in sqliteSendQuery(conn, statement, bind.data) : error in statement: no such table: 14m3-n4m3
This works if I choose a sensible name. However, due to a variety of reasons, I'd really like to keep the cumbersome names. I am also able to create such a badly-named table directly from sqlite:
Without cracking into things too deeply, this looks like dplyr is handling the square brackets in some way that I cannot figure out. My suspicion is that this is a bug, but I wanted to check here first to make sure I wasn't missing something.
EDIT: I forgot to mention the case where I just pass the janky name directly to dplyr. This errors out as follows:
The text was updated successfully, but these errors were encountered: