tidyverse / dbplyr

Database (DBI) backend for dplyr

Home Page:https://dbplyr.tidyverse.org

Repository from Github https://github.comtidyverse/dbplyrRepository from Github https://github.comtidyverse/dbplyr

copy_to(overwrite=TRUE) not working in duckdb and dbplyr

arthurgailes opened this issue · comments

It works fine for a dataframe, but not for a lazy_tbl.

library(duckdb)
#> Loading required package: DBI
library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.2.3
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
con <- dbConnect(duckdb())

copy_to(con, mtcars, "mtcars", temporary = FALSE)
copy_to(con, mtcars, "mtcars", overwrite = TRUE, temporary = FALSE)

mtcars_sql <- tbl(con, "mtcars")

copy_to(con, mtcars_sql, "mtcars2", temporary = FALSE)
copy_to(con, mtcars_sql, "mtcars2", overwrite = TRUE, temporary = FALSE)
#> Error in `db_compute()`:
#> ! Can't copy query to table mtcars2.
#> Caused by error in `db_save_query.DBIConnection()`:
#> ! Can't save query to table mtcars2.
#> ℹ Using SQL: CREATE TABLE mtcars2 AS SELECT * FROM mtcars
#> Caused by error:
#> ! rapi_execute: Failed to run query
#> Error: Catalog Error: Table with name "mtcars2" already exists!

dbDisconnect(con)

Created on 2024-08-14 with reprex v2.1.0