You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changed the Generics API Select signature from string to any so it matches DB.Select. This allows passing []string directly and fixes incorrect SQL generation when using dynamic field lists.
User Case Description
This fixes issue #7743 When the selected columns are built dynamically as []string, the previous Generics API required using Select("?", fields), which could generate incorrect SQL in PostgreSQL by treating column names as string literals. After this change, callers can use gorm.GUser.Select(fields) directly, consistent with the underlying API.
Align generics Select signature with DB.Select and add array-input SQL regression test
This PR updates the generics API so Select accepts interface{} instead of string, matching the underlying DB.Select behavior. The change is applied consistently across the CreateInterface, ChainInterface, and both concrete implementations (createG and chainG) in generics.go.
A new test in tests/generics_test.go verifies that passing []string to gorm.G[User](tx).Select([]string{"id", "name"}) generates a proper column list SQL statement and does not render column names as string literals (e.g., ('id','name')). This directly addresses issue #7743 and validates the intended PostgreSQL-safe behavior for dynamic field lists.
Key Changes
• Changed Select method signatures from Select(query string, args ...interface{}) to Select(query interface{}, args ...interface{}) in CreateInterface[T] and ChainInterface[T] within generics.go.
• Updated concrete methods createG[T].Select and chainG[T].Select in generics.go to accept interface{} and forward to db.Select(query, args...).
• Added TestGenericsSelectWithArrayInput in tests/generics_test.go to validate SQL generation when Select receives []string.
• Test asserts both positive SQL shape (contains selected columns) and negative case (does not contain tuple-like string literals).
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
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.
What did this pull request do?
Changed the Generics API Select signature from string to any so it matches DB.Select. This allows passing []string directly and fixes incorrect SQL generation when using dynamic field lists.
User Case Description
This fixes issue #7743 When the selected columns are built dynamically as []string, the previous Generics API required using Select("?", fields), which could generate incorrect SQL in PostgreSQL by treating column names as string literals. After this change, callers can use gorm.GUser.Select(fields) directly, consistent with the underlying API.