-
Notifications
You must be signed in to change notification settings - Fork 690
Fix UNION with ORDER BY parsing error #2417
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
Draft
Copilot
wants to merge
5
commits into
develop
Choose a base branch
from
copilot/fix-union-order-by-issue
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+272
−10
Conversation
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
Member
|
Continue |
Member
|
@copilot Continue... |
- Modified alasqlparser.jison to allow ORDER BY before UNION - Updated Select grammar rule to support OrderClause LimitClause UnionClause OrderClause LimitClause sequence - Regenerated alasqlparser.js from jison grammar - Added test2362.js to verify the fix - All existing UNION tests still pass Co-authored-by: mathiasrw <[email protected]>
Contributor
Author
I've completed the fix for the UNION with ORDER BY issue. The parse error has been resolved by modifying the grammar to allow ORDER BY clauses before UNION statements. All tests are passing. (commit: 1830831)
Done! The fix is complete. The grammar now accepts ORDER BY before UNION, resolving the parse error from the issue. (commit: 1830831) |
Copilot
AI
changed the title
[WIP] Fix UNION with ORDER BY not working as expected
Fix UNION with ORDER BY parsing error
Jan 2, 2026
mathiasrw
requested changes
Jan 2, 2026
- Added 12 new test cases covering various combinations: - ORDER BY DESC before UNION - LIMIT before UNION - ORDER BY + LIMIT before UNION - ORDER BY/LIMIT both before and after UNION - UNION ALL with ORDER BY before - EXCEPT with ORDER BY before - INTERSECT with ORDER BY before - Multiple UNIONs with ORDER BY - ORDER BY with multiple columns - ORDER BY with expressions - LIMIT with OFFSET before UNION - All 14 tests pass - All existing UNION tests still pass Co-authored-by: mathiasrw <[email protected]>
Co-authored-by: mathiasrw <[email protected]>
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.
Fixes the parse error that occurred when using ORDER BY before a UNION clause in SQL queries.
Issue
The parser was throwing a syntax error when ORDER BY was used before UNION:
Error:
Parse error on line 6: ...Y countryORDER BY UNIONSELECT "Total: ---------------------^ ... got 'UNION'Changes Made
src/alasqlparser.jison: Updated theSelectgrammar rule to support the sequenceOrderClause LimitClause UnionClause OrderClause LimitClause. This allows ORDER BY and LIMIT clauses to appear both before and after UNION operations.src/alasqlparser.js: Rebuilt the parser from the updated jison grammar file.test/test2362.js: Created comprehensive tests with 14 test cases to verify that ORDER BY and LIMIT can be used before UNION without parse errors and that existing UNION functionality remains intact.The grammar now supports:
SELECT ... ORDER BY ... UNION ...(ORDER BY before UNION)SELECT ... UNION ... ORDER BY ...(ORDER BY after UNION)SELECT ... ORDER BY ... UNION ... ORDER BY ...(both positions)Testing
The fix is minimal and focused, affecting only the grammar to accept the previously invalid syntax without altering the execution semantics.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.