Repository navigation
Bind up to 65535 parameters per statement - #35
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)threwInexactError: trunc(Int16, 32768)before sending anything.DBInterface.prepare(andexecutemany, which prepares) failed withinvalid ParameterDescription count from serverand closed the connection.This writes and reads both counts as
UInt16, through one helper used at all four Bind sites (unnamed execute, prepared execute,executemanybatches, cursors). More than 65535 parameters now throws aPostgresInterfaceErrorthat 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:
mainagainst 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) andPostgres.cursor; 65536 throws the new error and the connection stays open.Bind Parameter Countintegration testset: 2 errors onmain, passes with the fix.Pkg.test()withPOSTGRES_REQUIRE_INTEGRATION=true(Dockerpostgres:16), Julia 1.12.6: 9245/9245 pass.🤖 Generated with Claude Code