Repository navigation
Description
Kirill, I'm finally catching up on the RPostgres version, thanks for your efforts on this.
I'm confident that the switch to bit64::integer64 as the default was not made hastily, and I'm glad we have the capability. Since there are many aspects of base R that deal silently-incorrectly with this type, has there been discussion on being able to switch the bigint= argument per-query or even per-column?
Use Case: pre-existing processes that may rely on significant external code that either have unknown or known-bad compatibility with bit64::integer64, but with a connection where 64-bit numbers are needed for some fields. Setting it in dbConnect would still be relevant (as the default), but it'd be nice to be able to still use 64-bits when needed.
con <- dbConnect(..., bigint="integer")
dbGetQuery(con, "select 1 as a") # uses the dbConnect option
dbGetQuery(con, "select 1 as a", bigint="integer64") # overridesIt's likely going too far, but would anyone see utility in doing it per-column? The workaround until then would be to split the query into two, but this has the potential of being rather inefficient SQL-wise.
dbGetQuery(con, "select 1 as isbig, 2 as isnotbig", bigint=c(isbig="integer64",isnotbig="integer"))where the code might be:
convert_bigint_fields <- function (conn, ret, bigint = conn@bigint) {
bignms <- names(bigint)
if (is.null(bignms)) {
bigint <- setNames(rep(bigint, ncol(ret)), colnames(ret))
}
# set all others as default
bigint[ setdiff(colnames(ret), names(bigint)) ] <- 'default'
# reorder them
bigint <- bigint[colnames(ret)]
is_int64 <- vlapply(ret, inherits, "integer64")
funs <- list(integer = as.integer, numeric = as.numeric, character = as.character)
for (funnm in names(funs)) {
istype <- is_int64 & (bigint == funnm)
ret[istype] <- lapply(ret[istype], funs[[funnm]])
}
ret
}
Activity
krlmlr commentedon Apr 30, 2018
Thanks, Bill. I'm considering
biginta band-aid, more sophisticated ways are discussed in https://github.com/r-dbi/DBI/issues/137. Providingbigintper query seems straightforward and useful, but in the end perhaps it's easier if you consistently used custom wrappers arounddbFetch()anddbGetQuery()that took care of the conversion?The way the
bigintargument is currently implemented is just a post-processing as one of the last steps indbFetch(). This does add a penalty for anything other thanbigint = "integer64", but it works, and the penalty is likely relevant only for large volumes of data.r2evans commentedon May 1, 2018
I can see some simplicity in doing self-recovery post-
dbFetch, certainly, and it keeps things clean from your perspective. I think I fully grok the concept in DBI/137, I'll wait to see how that pans out. Thanks, Kirill.krlmlr commentedon Sep 25, 2021
Now that we have ALTREP it feels more prudent to focus efforts on providing an ALTREP-based view on the data returned from the database, with conversion as necessary after fetching the data.
github-actions commentedon Sep 26, 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.