Skip to content

Bind up to 65535 parameters per statement - #35

Merged
quinnj-bot[bot] merged 1 commit into
mainfrom
claude/bind-param-count
Oct 30, 2026
Merged

quinnj-bot[bot] merged 1 commit into
mainfrom
claude/bind-param-count

Conversation

@quinnj-bot

@quinnj-bot quinnj-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

PostgreSQL reads the Bind message's parameter count as unsigned 16 bits, and libpq binds up to 65535 parameters. Postgres.jl wrote the count with Int16, and read the ParameterDescription count the same way. So with more than 32767 parameters:

  • DBInterface.execute(conn, sql, params) threw InexactError: trunc(Int16, 32768) before sending anything.
  • DBInterface.prepare (and executemany, which prepares) failed with invalid ParameterDescription count from server and closed the connection.

This writes and reads both counts as UInt16, through one helper used at all four Bind sites (unnamed execute, prepared execute, executemany batches, cursors). More than 65535 parameters now throws a PostgresInterfaceError that names the limit, before anything is sent, so the connection stays usable. Preparing a statement with more than 65535 placeholders still fails (PostgreSQL truncates its count), but the error now names the limit instead of reporting a bad message length.

Fixes #34

Verification:

  • Reproduced on main against PostgreSQL 14.19 (Homebrew): unnamed execute fails from 32768 parameters, prepare fails and closes the connection. With the fix, 32768, 40000 and 65535 parameters return the right result on unnamed execute, prepared execute, executemany (3 rows of 40000) and Postgres.cursor; 65536 throws the new error and the connection stays open.
  • New Bind Parameter Count integration testset: 2 errors on main, passes with the fix.
  • Full Pkg.test() with POSTGRES_REQUIRE_INTEGRATION=true (Docker postgres:16), Julia 1.12.6: 9245/9245 pass.

🤖 Generated with Claude Code

PostgreSQL reads the Bind message's parameter count, and writes the
ParameterDescription count, as unsigned 16 bits (libpq allows 65535).
Postgres.jl wrote the count with Int16, so a statement with more than
32767 parameters threw InexactError before sending, and read the
ParameterDescription count as Int16, so preparing one closed the
connection with "invalid ParameterDescription count".

Write and read the counts as UInt16. More than 65535 parameters now
throws a PostgresInterfaceError before anything is sent, and preparing a
statement with more placeholders than that names the limit.

Fixes #34

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@quinnj-bot
quinnj-bot Bot merged commit c1b9074 into main Oct 30, 2026
16 checks passed
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.

Bind parameter count is encoded as Int16: statements with more than 32767 parameters raise InexactError

1 participant