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

Fix copy_to overwrite flag #1580

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# dbplyr (development version)

* Fixed overwrite flag in `copy_to` to work when source is in the same remote DB
as destination (@liudvikasakelis, #1535)

* Tightened argument checks for SQL translations. These changes should
result in more informative errors in cases where code already failed, possibly
silently; if you see errors with code that used to run correctly, please report
Expand Down
2 changes: 2 additions & 0 deletions R/verb-compute.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ collapse.tbl_sql <- function(x, ...) {
compute.tbl_sql <- function(x,
name = NULL,
temporary = TRUE,
overwrite = FALSE,
unique_indexes = list(),
indexes = list(),
analyze = TRUE,
Expand Down Expand Up @@ -62,6 +63,7 @@ compute.tbl_sql <- function(x,

name <- db_compute(x$src$con, name, sql,
temporary = temporary,
overwrite = overwrite,
unique_indexes = unique_indexes,
indexes = indexes,
analyze = analyze,
Expand Down
1 change: 1 addition & 0 deletions R/verb-copy-to.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ copy_to.src_sql <- function(dest,
out <- compute(df,
name = name,
temporary = temporary,
overwrite = overwrite,
unique_indexes = unique_indexes,
indexes = indexes,
analyze = analyze,
Expand Down
5 changes: 5 additions & 0 deletions man/collapse.tbl_sql.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/testthat/test-verb-copy-to.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ test_that("only overwrite existing table if explicitly requested", {
expect_silent(copy_to(con, data.frame(x = 1), name = "df", overwrite = TRUE))
})

test_that("overwrite flag works when copying *within* db sources", {
con <- local_sqlite_connection()
df <- copy_to(con, tibble(x = 1:10), "df", temporary = FALSE)
copy_to(con, df, "df2", temporary = FALSE)

expect_error(copy_to(con, df, name = "df2", temporary = FALSE), "exists")
expect_silent(copy_to(con, df, name = "df2", temporary = FALSE, overwrite = TRUE))
})

test_that("can create a new table in non-default schema", {
con <- local_sqlite_con_with_aux()

Expand Down
Loading