tidyverse / dbplyr

Database (DBI) backend for dplyr
https://dbplyr.tidyverse.org
Other
469 stars 169 forks source link

sql_cast_dispatch does not handle raw or blob (from tidyverse::blob) classes #1515

Open avsdev-cw opened 3 weeks ago

avsdev-cw commented 3 weeks ago

sql_cast_dispatch in copy_to (also called by copy_inline) has no overload to handle the blob (or raw) class.

It currently produces the error:

dbplyr::copy_inline(dbplyr::simulate_dbi(), tibble::tibble(blob::new_blob()))
#> Error in `purrr::map2_chr()`:
#> ℹ In index: 1.
#> ℹ With name: blob::new_blob().
#> Caused by error in `UseMethod()`:
#> ! no applicable method for 'sql_cast_dispatch' applied to an object of class "c('blob', 'vctrs_list_of', 'vctrs_vctr', 'list')"

Created on 2024-06-11 by the reprex package (v2.0.0)

The only option I have found is to encase the raw in a blob (if it isn't already) then manually escape using dbplyr::escape (there is no overload for raw but there is for blob). This then uses the sql class overload.

I should also note that this is particularly confusing as dbplyr will automatically use blob class type for blob columns when retrieving tables from the database.