Repository navigation
fix: Explain how to bind a named stream in dbBindArrow() - #658
Conversation
`dbBindArrow()` rejects a stream with named columns, as the DBI specification and DBItest require for positional placeholders, but the error did not say how to bind such a stream. The error now names the positional matching and the fix, and the documentation of `params` says that names are not allowed. Tests pin the error for `dbBind()` and `dbBindArrow()` and the positional binding of a stream with empty column names. Closes #642. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
Question: Keep rejecting named stream columns in
|
A stream passed as `params` to `dbSendQueryArrow()` or `dbGetQueryArrow()` reaches `dbBind()` unconverted, with the names of its methods, so the advice to empty its column names was wrong. It now says to bind a stream with `dbBindArrow()` after `dbSendQueryArrow()`. The error for named parameters names the recipe for an unnamed stream, and `nanoarrow` is listed in Suggests only, not in VignetteBuilder. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
Addresses #642. This PR settles #642 as "keep the error", pending Kirill's answer to the question comment; it will say "Closes #642" only if that option is ticked.
dbBindArrow()keeps rejecting a stream with named columns, but the error now says why and how to fix it: "paramsmust not be named: RPostgres matches parameters to $1, $2, ... by position. Remove the names withunname(), fordbBindArrow()by callingunname()on the data frame beforenanoarrow::as_nanoarrow_array_stream()." The documentation ofparamsin?postgres-querysays the same.A nanoarrow stream passed as
paramstodbSendQueryArrow()ordbGetQueryArrow()reachesdbBind()unconverted, and its names are those of its methods, so the advice above would be wrong there. It gets its own error instead: "paramsmust not be a nanoarrow stream here: bind a stream withdbBindArrow()afterdbSendQueryArrow()." That path is broken onmaintoo and is fixed separately.Why keep the error:
dbBind()anddbBindArrow()says: "If the placeholders in the query are named, all parameter values must have names (which must not be empty orNA), and vice versa, otherwise an error is raised." DBItest 1.9.0 checks exactly the reprex ofdbBindArrow()rejects every stream with named columns #642 inarrow_stream_bind_unnamed_param_named_placeholders: a stream with a column namedabound to$1must raise an error. The same check exists fordbBind()(bind_unnamed_param_named_placeholders) and fordbBind()on an Arrow result (arrow_bind_unnamed_param_named_placeholders). All three pass onmainand with this PR.dbBindArrow()method. The draft native Arrow bind in RSQLite (feat: Bind the rows of an Arrow stream to a statement RSQLite#866) keeps that error for Arrow streams too.dbBindArrow()method forPqResultwould not fix the reprex:dbSendQueryArrow()returns DBI'sDBIResultArrowDefault, whose owndbBindArrow()method callsdbBind()on the wrappedPqResultwith a named list, so an RPostgres method onPqResultis never reached. Only relaxingdbBind()itself, or a nativedbSendQueryArrow()(planned in chore: Coordinate native Arrow support #631), can change the behavior.Changes:
R/dbBind_PqResult.R: actionable error messages for named parameters and for a stream passed asparams.R/PqResult.R,man/postgres-query.Rd: document positional matching.tests/testthat/test-dbBind.R: self-contained tests for both errors, fromdbBind()anddbBindArrow(), and for positional binding of a stream with empty column names viaunname().DESCRIPTION:nanoarrowin Suggests, for the new tests (skipped when it is not installed).No change to
helper-DBItest.Ris needed: the DBItest Arrow bind specs already cover named columns for$1placeholders and expect the error. The new test file and the DBItest Arrow bind specs pass against PostgreSQL 16 locally, as did the full suite at the first commit.The PR touches neither
R/export.RnorNAMESPACE, so it does not conflict with #634.DESCRIPTIONmay conflict trivially with other open PRs that edit Suggests.Coordination of native Arrow support: #631.
Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
🤖 Generated with Claude Code
https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g