Skip to content

dbGetQueryArrow() and dbSendQueryArrow() reject every Arrow stream passed as params #661

Done

Description

@krlmlr

Passing a nanoarrow array stream as params = to dbGetQueryArrow() or dbSendQueryArrow() fails with "params must not be named." for every stream, including one whose columns have empty names. The stream itself is a named list of functions (get_schema, get_next, release), and RPostgres checks names(params) on it. The same stream binds fine with dbSendQueryArrow() followed by dbBindArrow(), and a plain list works with params =. The failed call also leaves its result set open, hence the "Closing open result set" warning on the next query below.

Severity: high (proposed, Kirill may change), since it makes params = unusable with Arrow streams on the Arrow path.

Reprex against the CRAN release:

Sys.setenv(PGHOST = "localhost", PGPORT = "5432", PGUSER = "runner", PGPASSWORD = "test123", PGDATABASE = "arrowparams")
library(DBI)
con <- dbConnect(RPostgres::Postgres())
p <- nanoarrow::as_nanoarrow_array_stream(unname(data.frame(a = 1L)))
names(p)
#> [1] "get_schema" "get_next"   "release"
dbGetQueryArrow(con, "SELECT $1::int AS a", params = p)
#> Error:
#> ! `params` must not be named.
# Expected: a stream with one row, a = 1

# The same stream works with dbBindArrow()
p <- nanoarrow::as_nanoarrow_array_stream(unname(data.frame(a = 1L)))
rs <- dbSendQueryArrow(con, "SELECT $1::int AS a")
#> Warning: Closing open result set, cancelling previous query
dbBindArrow(rs, p)
as.data.frame(dbFetchArrow(rs))
#>   a
#> 1 1
dbClearResult(rs)

# A plain list works with params =
as.data.frame(dbGetQueryArrow(con, "SELECT $1::int AS a", params = list(1L)))
#>   a
#> 1 1

dbGetQuery(con, "SHOW server_version")
#>                          server_version
#> 1 16.15 (Ubuntu 16.15-0ubuntu0.24.04.1)
dbDisconnect(con)
as.data.frame(sessioninfo::package_info(c("RPostgres", "DBI", "nanoarrow"), dependencies = FALSE))[c("package", "ondiskversion", "source")]
#>             package ondiskversion         source
#> DBI             DBI         1.3.0           RSPM
#> nanoarrow nanoarrow         0.9.0           RSPM
#> RPostgres RPostgres        1.4.10 RSPM (R 4.5.0)

Created on 2026-11-29 with reprex v2.1.1

Code path

  • DBI's default dbGetQueryArrow() forwards ... to dbSendQueryArrow(), and the default dbSendQueryArrow() calls dbSendQuery(conn, statement, params = params, ...) with the stream unchanged.
  • RPostgres dbSendQuery() calls dbBind(rs, params), and dbBind() errors because names(params) of the stream is not NULL (links pinned to the v1.4.10 release commit).
  • dbBindArrow() works because DBI's DBIResultArrowDefault method first converts the stream with param_stream_to_list(), which drops all-empty column names. The params = path skips that conversion.

Why DBItest does not catch it

DBItest 1.9.0 passes params = to these functions only as a plain list, in arrow_get_query_arrow_params and arrow_send_query_params. Both run (they are not in the skip list of helper-DBItest.R) and pass against the CRAN release. Streams appear only in the dbBindArrow() specs, which take the conversion path above. The specs say only "The param argument allows passing query parameters, see [dbBind()] for details", so whether a stream is valid for params = is not specified either.

Fix

Native Arrow support (#631) would fix this, since a native dbSendQueryArrow() can bind the stream itself. Meanwhile, #658 adjusts the "must not be named" error message, which does not change this behavior. Related: #641, #642.

  • fix: accept an Arrow stream as params in dbSendQueryArrow() and dbGetQueryArrow(), and do not leak the result set when binding fails
  • test: params = with a stream, for both functions (possibly as a DBItest spec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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