Skip to content
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

Trying to dbAppendTable with an empty data frame throws "Error: Cannot pass NA to dbQuoteIdentifier()" #313

Closed
Kodiologist opened this issue Feb 10, 2020 · 3 comments · Fixed by #335
Labels
Milestone

Comments

@Kodiologist
Copy link

What I would've expected is for such a call to silently do nothing. Then, when the value argument to dbAppendTable is an expression yielding a data frame of 0 or more rows (and in the case of 0 rows, 0 columns as well), everything works as expected when 0 rows are produced. Even if you don't want to allow this, improving the error message is probably wise.

library(DBI)
db = dbConnect(RSQLite::SQLite(), ":memory:")
dbExecute(db, "create table T(n  integer primary key)")
dbAppendTable(db, "T", data.frame())
@krlmlr krlmlr transferred this issue from r-dbi/RSQLite Apr 17, 2020
@krlmlr krlmlr added the bug label Apr 17, 2020
@krlmlr
Copy link
Member

krlmlr commented Apr 17, 2020

Thanks for raising this. We need to fix DBI::sqlAppendTableTemplate() to account for zero-length input.

@krlmlr krlmlr added this to the 1.1.1 milestone Dec 27, 2020
@krlmlr
Copy link
Member

krlmlr commented Jan 2, 2021

You need to pass in columns, even if they have no rows:

library(DBI)
db <- dbConnect(RSQLite::SQLite(), ":memory:")
dbExecute(db, "create table T(n  integer primary key)")
#> [1] 0
dbAppendTable(db, "T", data.frame(n = integer()))
#> [1] 0

Created on 2021-01-02 by the reprex package (v0.3.0)

Working on improving the error message for your example.

krlmlr added a commit that referenced this issue Jan 3, 2021
- `dbAppendTable()` shows a better error message if the input has zero columns (#313).
@github-actions
Copy link

github-actions bot commented Jan 4, 2022

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants