Skip to content

fix: Explain how to bind a named stream in dbBindArrow() - #658

Merged
krlmlr merged 2 commits into
mainfrom
claude/fix-bind-arrow-names
Nov 29, 2026
Merged

krlmlr merged 2 commits into
mainfrom
claude/fix-bind-arrow-names

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

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: "params must not be named: RPostgres matches parameters to $1, $2, ... by position. Remove the names with unname(), for dbBindArrow() by calling unname() on the data frame before nanoarrow::as_nanoarrow_array_stream()." The documentation of params in ?postgres-query says the same.

A nanoarrow stream passed as params to dbSendQueryArrow() or dbGetQueryArrow() reaches dbBind() unconverted, and its names are those of its methods, so the advice above would be wrong there. It gets its own error instead: "params must not be a nanoarrow stream here: bind a stream with dbBindArrow() after dbSendQueryArrow()." That path is broken on main too and is fixed separately.

Why keep the error:

  • The DBI specification of dbBind() and dbBindArrow() says: "If the placeholders in the query are named, all parameter values must have names (which must not be empty or NA), and vice versa, otherwise an error is raised." DBItest 1.9.0 checks exactly the reprex of dbBindArrow() rejects every stream with named columns #642 in arrow_stream_bind_unnamed_param_named_placeholders: a stream with a column named a bound to $1 must raise an error. The same check exists for dbBind() (bind_unnamed_param_named_placeholders) and for dbBind() on an Arrow result (arrow_bind_unnamed_param_named_placeholders). All three pass on main and with this PR.
  • The strictness is intentional (Confusing error for names in parameterized queries #266: "The strictness here is intentional -- named placeholders require named parameters, same with unnamed.").
  • RMariaDB and RSQLite reject named parameters for positional placeholders the same way, and neither has its own 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.
  • A dbBindArrow() method for PqResult would not fix the reprex: dbSendQueryArrow() returns DBI's DBIResultArrowDefault, whose own dbBindArrow() method calls dbBind() on the wrapped PqResult with a named list, so an RPostgres method on PqResult is never reached. Only relaxing dbBind() itself, or a native dbSendQueryArrow() (planned in chore: Coordinate native Arrow support #631), can change the behavior.
  • The ADBC PostgreSQL driver, by contrast, binds stream columns by position and never reads their names. That is an argument for ignoring names once the native bind in chore: Coordinate native Arrow support #631 lands, which can decide it together with a change to the DBI specification.

Changes:

  • R/dbBind_PqResult.R: actionable error messages for named parameters and for a stream passed as params.
  • R/PqResult.R, man/postgres-query.Rd: document positional matching.
  • tests/testthat/test-dbBind.R: self-contained tests for both errors, from dbBind() and dbBindArrow(), and for positional binding of a stream with empty column names via unname().
  • DESCRIPTION: nanoarrow in Suggests, for the new tests (skipped when it is not installed).

No change to helper-DBItest.R is needed: the DBItest Arrow bind specs already cover named columns for $1 placeholders 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.R nor NAMESPACE, so it does not conflict with #634. DESCRIPTION may 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

`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

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Question: Keep rejecting named stream columns in dbBindArrow(), or bind them by position?

dbBindArrow() with DBI's default methods turns the stream into a named list and calls dbBind(), which rejects names because RPostgres has only positional placeholders ($1, $2). Every stream made from a data frame or Arrow table has named columns, so the common case errors (#642). The DBI specification requires that error ("If the placeholders in the query are named, all parameter values must have names [...], and vice versa, otherwise an error is raised"), DBItest 1.9.0 checks it for dbBindArrow() in arrow_stream_bind_unnamed_param_named_placeholders with exactly the reprex of #642, #266 calls the strictness intentional, and RSQLite and RMariaDB behave the same. A dbBindArrow() method for PqResult cannot help, because dbSendQueryArrow() returns DBI's DBIResultArrowDefault, whose own method calls dbBind() on the wrapped PqResult directly. The ADBC PostgreSQL driver, on the other hand, binds stream columns by position and ignores their names.

  • (recommended) Keep the error, as the specification requires, and make it actionable: it says that parameters match $1, $2 by position and how to drop the names; ?postgres-query documents it. Cost: users still have to unname their streams. Revisit with the native bind in chore: Coordinate native Arrow support #631, together with a DBI specification change for Arrow streams if names should be ignored there. This is what the PR does now.
  • Let dbBind() ignore names and bind by position (option 2 of dbBindArrow() rejects every stream with named columns #642). Smallest change that makes the reprex work, about three lines. Cost: it breaks the DBI specification for dbBind() too, needs three DBItest skips (bind_unnamed_param_named_placeholders, arrow_bind_unnamed_param_named_placeholders, arrow_stream_bind_unnamed_param_named_placeholders), and a list or data frame whose names suggest a different order binds silently in the wrong order, which Confusing error for names in parameterized queries #266 rejected.
  • Own dbSendQueryArrow() for PqConnection returning an RPostgres subclass with a dbBindArrow() method that drops names, leaving dbBind() strict. Cost: a new result class and methods ahead of the native Arrow work in chore: Coordinate native Arrow support #631, plus one DBItest skip (arrow_stream_bind_unnamed_param_named_placeholders) and a specification deviation for dbBindArrow() only.

Kirill decides, as maintainer of RPostgres and DBI. If nobody decides, the PR stays with the first option and #642 closes with the improved error.


Generated by Claude Code

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
@krlmlr
krlmlr marked this pull request as ready for review November 29, 2026 12:23
@krlmlr
krlmlr added this pull request to stack #663 November 29, 2026 12:24
@krlmlr krlmlr mentioned this pull request Nov 29, 2026
3 of 9 tasks
@krlmlr
krlmlr merged commit c19ffc7 into main Nov 29, 2026
9 checks passed
@krlmlr
krlmlr deleted the claude/fix-bind-arrow-names branch November 29, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dbBindArrow() rejects every stream with named columns

2 participants