Skip to content

dbExecute(params=) does not work #663

@r2evans

Description

@r2evans

7423412 adds support for parameterized queries (resolving #191), but it seems inconsistent with the DBI interface: dbGetQuery(..., params=) works, but dbExecute(..., params=) does not work yet dbExecute(..., parameters=) does work.

bqcon <- DBI::dbConnect(bigrquery::bigquery(), ...) # the connection works
ds <- bigrquery::bq_table(..., table = "r2test")
tbl <- tibble(bool=c(T,F,NA), int=c(0:1, NA), dbl=c(0, 1, NA), chr=c("Yay","Nay",NA),
              dat=c(rep(Sys.Date(),2),NA), psx=c(rep(Sys.time(), 2), NA)) |>
  mutate(psxdbl = as.numeric(psx))
bigrquery::bq_table_upload(ds, tbl)

DBI::dbGetQuery(bqcon, "select * from r2test where chr=@a", params=list(a='Yay'))
# # A tibble: 1 × 7
#   psx                     dat             psxdbl chr     int   dbl bool 
#   <dttm>                  <date>           <dbl> <chr> <int> <dbl> <lgl>
# 1 2026-01-09 14:00:59.349 2026-01-09 1767967258. Yay       1  3.14 TRUE 
DBI::dbGetQuery(bqcon, "select * from r2test where chr=@a", parameters=list(a='Yay'))
# Error in bq_perform_query(sql, billing = conn@billing, default_dataset = ds,  (from dbi-result.R#6) : 
#   formal argument "parameters" matched by multiple actual arguments

DBI::dbExecute(bqcon, "update r2test set int=9 where chr=@a", params = list(a="Yay"))
# Error in `DBI::dbExecute()`:
# ! Job track-services-prod.job_3vo5v57ttFvSvBy5ftM7r7OxAos_.US failed
# ✖ Query parameter 'a' not found at [1:35] [invalidQuery]
# Run `rlang::last_trace()` to see where the error occurred.
DBI::dbExecute(bqcon, "update r2test set int=9 where chr=@a", parameters = list(a="Yay"))
# [1] 1

I suggest that dbExecute should be using params= directly, and both functions perhaps should recognize the use of parameters= and deal with it appropriately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions