Skip to content

Allow up to 65535 query arguments - #1391

Open
HardMax71 wants to merge 1 commit into
MagicStack:masterfrom
HardMax71:fix/unsigned-parameter-count
Open

HardMax71 wants to merge 1 commit into
MagicStack:masterfrom
HardMax71:fix/unsigned-parameter-count

Conversation

@HardMax71

Copy link
Copy Markdown

Fixes #1390.

PostgreSQL reads the 16-bit parameter count in Bind as unsigned and documents a limit of 65,535 query parameters, but asyncpg keeps the count in int16_t and refuses more than 32767 arguments (the check from #127).

  • args_num and the ParameterDescription count are uint16_t now. Bind still writes them with write_int16 through an int16_t cast, so the bytes on the wire are the same as before for up to 32767 arguments.
  • The argument check allows up to 65535 and names that number.
  • test_prepare_28_max_args now runs a query with 65535 arguments and expects the error at 65536.

Tested against PostgreSQL 17 (PGHOST pointing at a local server): test_prepare, test_execute, test_codecs, test_cursor, test_copy, test_cache_invalidation, test_record, test_introspection, test_exceptions and test_timeout pass (197 passed, 3 skipped), and flake8 asyncpg tests is clean. The updated test fails on master. The script from the issue now prints the same counts for asyncpg and psycopg at 32767, 32768 and 65535 arguments, and a multi-row INSERT with 40000 parameters goes through.

PostgreSQL reads the 16-bit parameter counts in Bind and
ParameterDescription as unsigned and documents a limit of 65,535 query
parameters, but asyncpg stored them in int16_t and refused more than
32767 arguments. Keep the count as uint16_t and raise the limit to 65535.

This branch has not been deployed

No deployments
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.

Queries with more than 32767 arguments are refused, PostgreSQL accepts 65535

1 participant