-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(database/gdb): Resolve column ambiguity in GROUP BY/ORDER BY with MySQL JOIN #4521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(database/gdb): Resolve column ambiguity in GROUP BY/ORDER BY with MySQL JOIN #4521
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR addresses the issue of ambiguous column names in MySQL GROUP BY clauses when using JOIN queries. When multiple tables share common column names (like id), unqualified column references in GROUP BY cause MySQL errors.
Key Changes:
- Changed
Group()method signature to accept...anyinstead of...stringto support Raw SQL expressions - Added auto-prefixing logic that detects JOINs and qualifies unqualified column names with the primary table name
- Preserved handling for already-qualified columns and Raw expressions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
database/gdb/gdb_model_order_group.go |
Modified Group() method to auto-prefix unqualified columns when JOINs are detected, supporting both string and Raw expression inputs |
contrib/drivers/mysql/mysql_z_unit_feature_model_join_test.go |
Added test case verifying GROUP BY works with JOIN queries without ambiguous column errors |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When using JOIN queries in MySQL with the
Group()method, column names in GROUP BY clauses become ambiguous if multiple tables contain columns with the same name (commonlyid). This results in MySQL errors like "Column 'id' in group statement is ambiguous".Example Issue:
Key Changes
Group(groupBy ...string)→Group(groupBy ...any)to support Raw SQL expressionsTest_Model_Group_WithJoinverifies the fix works correctly with JOIN queries