-
Notifications
You must be signed in to change notification settings - Fork 175
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
copy_to
creates tables with invalid column names
#1016
Comments
It feels quite unexpected to me that the database changes the column names. So, I'm not a big fan of the old behaviour. At least, this should be a warning. So it also does not make sense to me to add such a parameter. Instead you should rather rename the columns before copying. @hadley What's your opinion on that? |
Hmmmmmm, given that some databases do this, and we can't really protect it, it seems like it would be safest to ask the database for the column names, and then maybe warn the user if they're changed from what they supplied? |
Can we:
|
This seems reasonable to me. It avoids the roundtrip in most cases and should still be safe. |
This seems like a lot of work for a situation that seems to occur rarely. @jensmassberg can you give us more information about which database you're using and how the names are transformed? |
Closing as we are missing more details here. Happy to reopen if we get more information or this comes up more frequently. |
I use dbplyr with a database where some column names are invalid.
If a table with invalid column name is copied to the data base, invalid
names are changed to valid ones. Thus when using
copy_to
, the table in thedatabase might have column names than are different from the original data frame.
This was no problem in dbplyr 2.1.1, but in dbplyr 2.2.1 the returned tbl object
contains the old (invalid) column names instead of the new correct ones. This leads
to bugs when working with the table.
A closer look into the code showed that the following line led to the problem:
https://github.com/tidyverse/dbplyr/blame/main/R/verb-copy-to.R#L86
Before the line was changes, the column names were read from the table. Now it is
assumed that they are the same as the ones in the data frame. This assumption isn't
true in my case and I think that there are also other data bases where this isn't
necessarily true (random example: https://www.techtalkcorner.com/parquet-files-column-names-with-spaces/).
Can we either
copy_to
to read the column names from the table orThe text was updated successfully, but these errors were encountered: