Fix ambiguous column name error in ORDER BY clauses for JOIN queries #230
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.
This PR resolves an incompatibility between MySQL and SQLite when handling unqualified column names in ORDER BY clauses within JOIN queries.
Problem
SQLite treats ambiguous column names in ORDER BY clauses more strictly than MySQL. When a SELECT clause uses a fully qualified column reference but ORDER BY uses an unqualified reference to the same column, MySQL correctly infers the qualification while SQLite throws an "ambiguous column name" error.
For example, these queries work in MySQL but fail in SQLite:
Solution
The fix adds intelligent column qualification resolution at the
queryExpressionlevel in the AST translator. When an ORDER BY clause contains unqualified column references:Implementation Details
translate_query_expression_with_order_by_fix()method to handle ORDER BY qualificationTest Results
The fix successfully resolves the target cases while preserving expected failures:
✅ Now Working:
✅ Still Fail (As Expected):
✅ Edge Cases Handled:
Fixes #228.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/5b5e3821314f947dd040c70f7992a64eac89025c/usr/bin/php8.3 -n -c /tmp/WPw4p5 /usr/bin/composer install(http block)https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176/usr/bin/php8.3 -n -c /tmp/WPw4p5 /usr/bin/composer install(http block)https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74/usr/bin/php8.3 -n -c /tmp/WPw4p5 /usr/bin/composer install(http block)https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/6db563514f27e19595a19f45a4bf757b6401194e/usr/bin/php8.3 -n -c /tmp/WPw4p5 /usr/bin/composer install(http block)If you need me to access, download, or install something from one of these locations, you can either:
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.