Skip to content

feat: support case-insensitive query parameter matching#823

Open
olavloite wants to merge 2 commits into
mainfrom
feat/594-case-insensitive-params
Open

feat: support case-insensitive query parameter matching#823
olavloite wants to merge 2 commits into
mainfrom
feat/594-case-insensitive-params

Conversation

@olavloite

@olavloite olavloite commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Normalize bound parameter names case-insensitively against the parameter names parsed from the SQL statement. This allows using any case in database/sql named arguments (e.g. sql.Named('id', ...)) to match case-insensitive query parameters in the statement (e.g. @id).

Fixes #594

@olavloite olavloite requested a review from a team as a code owner June 11, 2026 12:35

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces case-insensitive matching for named parameters in Spanner statements, along with corresponding unit tests for both GoogleSQL and PostgreSQL dialects. The reviewer recommended checking for an exact match first before performing case-insensitive matching. This ensures determinism (since map iteration in Go is non-deterministic and could lead to incorrect matches if multiple casing variations exist) and improves performance by avoiding unnecessary loops and case-insensitive comparisons in the common case.

Comment thread stmt.go
@olavloite

Copy link
Copy Markdown
Collaborator Author

Great feature to support case-insensitive query parameter matching.

However, I have one critical correctness recommendation:
Currently, the code iterates over namesToIndex and names using strings.EqualFold to find a match. If a query contains both @id and @ID (which are valid and distinct in GoogleSQL), and the user passes sql.Named(\"ID\", 1), the case-insensitive loop might match @id first (since map iteration order is randomized).

To fix this and avoid non-deterministic behavior, we should check for an exact match first before falling back to the case-insensitive search loop. Checking for an exact match first will also optimize the hot path for queries where the casing matches exactly, avoiding the (N \times M)$ comparison loop entirely.

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.

Check whether query parameter names should be case-insensitive

1 participant