fix: don't treat @ inside a string literal as a named parameter in Select - #7827
Open
makoto-developer wants to merge 1 commit into
Open
fix: don't treat @ inside a string literal as a named parameter in Select#7827makoto-developer wants to merge 1 commit into
makoto-developer wants to merge 1 commit into
Conversation
…lect
When a string passed to Select contains an @, Select treats the whole
statement as a named expression and consumes the remaining arguments as
variables. If those arguments are plain column names, they are silently
dropped, e.g. Select("name = 'a@b.com' as x", "age") loses the age column.
Skip the named-expression path when every argument is a plain column name
(string or []string); a bare @ is then part of the SQL text. Passing named
arguments (sql.Named, maps, structs) is unaffected.
Fixes go-gorm#7235
makoto-developer
marked this pull request as ready for review
July 26, 2026 02:35
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.
Description
Fixes #7235
When a string passed to
Selectcontains an@,Selecttreats the whole statement as a named expression (clause.NamedExpr) and consumes the following arguments as its variables. When those arguments are plain column names, they are silently dropped:The
@here is part of a string literal, not a named-parameter placeholder.Fix
Skip the named-expression path when every extra argument is a plain column name (
stringor[]string); in that case a bare@is just part of the SQL text and the arguments are treated as additional columns, matching the[]stringform ofSelect.Passing actual named arguments (
sql.Named, maps, structs) still takes the named-expression path and is unaffected — the existingCOALESCE(age, @default)test continues to pass.Testing
Added
TestSelectWithAtInStringLiteral(fails before, passes after).go test ./...passes for both the root module and thetestsmodule;golangci-lintreports no new issues;gofumpt/go vetclean.