Skip to content

Preserve unquoted dollar identifiers in simple protocol queries - #2724

Open
Twiink wants to merge 1 commit into
jackc:masterfrom
Twiink:fix/simple-protocol-dollar-identifiers
Open

Twiink wants to merge 1 commit into
jackc:masterfrom
Twiink:fix/simple-protocol-dollar-identifiers

Conversation

@Twiink

@Twiink Twiink commented Nov 20, 2026

Copy link
Copy Markdown

Queries that reference legal unquoted PostgreSQL names such as value$1 or value$tag$ work with extended protocol but fail with QueryExecModeSimpleProtocol. The SQL sanitizer treats a dollar suffix inside the name as a parameter or a dollar-quote opener, causing syntax errors, insufficient arguments or unused-argument errors.

Consume each complete unquoted identifier before looking for the next SQL token, matching the existing NamedArgs lexer. PostgreSQL allows dollar signs after the first identifier character. The actual parameter following the identifier continues to bind normally; the public API and dependencies are unchanged.

Validation:

  • On unchanged master 0b03cad, four simple-protocol cases fail against PostgreSQL 18.6; the identical four extended-protocol controls pass. All eight pass after the fix, along with four exact-SQL sanitizer regressions.
  • Complete go test -race ./... passes against PostgreSQL 18.6, including existing dollar-quote and sanitizer regressions. Optional TLS/auth/PgBouncer/CockroachDB configurations and the full OS/Go/database matrix were not run.
  • goimports, gofumpt and diff checks pass. go vet . ./internal/sanitize passes. Whole-repository vet reports the same 117 pre-existing unkeyed-literal diagnostics in pgtype on pristine master and the patch.
  • golangci-lint 2.15.0 reports the same two existing gocritic findings on pristine master and the patch (pgconn/auth_policy_test.go:316, pgtype/multirange.go:390); checking new issues reports zero.

AI proposal: prepared by Codex (GPT-6). The task prompt was to find an independent backend bug, check existing issues/PRs/commits, reproduce it before changing production, implement a minimal fix and validate it. The investigation compared the two SQL lexers, exercised both protocols against a real database, and reviewed the complete final diff.

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.

1 participant