Conversation
…]) syntax <!-- COPILOT_AI_GENERATED_START --> # Fix invalid OVER clause parsing - reject OVER([col]) syntax ## Summary Fixed a parser bug where invalid OVER clause syntax like `COUNT(*) OVER([col])` was incorrectly accepted. The parser now properly rejects OVER clauses that contain only an identifier in parentheses without PARTITION BY or ORDER BY clauses. ## Problem The parser was accepting invalid syntax such as: ```sql SELECT COUNT(*) OVER([col]) FROM t1 SELECT SUM(Amount) OVER(MyColumn) FROM t1 ``` This is invalid because an OVER clause with parentheses must contain one of: - `PARTITION BY` clause - `ORDER BY` clause - Window frame clause - Or be empty: `OVER()` Valid window name references (introduced in SQL Server 2022) must be written WITHOUT parentheses: ```sql SELECT SUM(c1) OVER Win1 FROM t1 WINDOW Win1 AS (PARTITION BY c1) ``` Additionally, partial window specifications CAN include a window name inside parentheses, but ONLY when combined with other clauses: ```sql SELECT SUM(c1) OVER (Win1 ORDER BY c2) FROM t1 WINDOW Win1 AS (PARTITION BY c1) ``` ## Root Cause In SQL Server 2022 (TSql160), support was added for the WINDOW clause feature, which allows referencing named windows. The grammar rule `overClauseBeginning` was modified to accept an optional identifier inside parentheses to support partial window specifications like `OVER (Win1 PARTITION BY ...)`. However, the rule `overClauseNoOrderBy` (used by aggregate functions like COUNT, SUM, AVG) was still using `overClauseBeginning`, which meant it would accept `OVER(identifier)` and interpret the identifier as a window name, even though no other clauses were present. This resulted in invalid syntax being accepted. ## Solution Created a new grammar rule `overClauseBeginningNoWindowName` that does not allow window name identifiers inside parentheses. Modified `overClauseNoOrderBy` to use this new rule instead of `overClauseBeginning`. The new rule uses explicit alternatives instead of an optional clause to ensure ANTLR properly rejects identifiers that aren't followed by the `BY` keyword: ```antlr overClauseBeginningNoWindowName: OVER LeftParenthesis ( Identifier { Match("PARTITION") } BY expressionList | /* empty - allow OVER() with no PARTITION BY */ ) ``` This ensures that when parsing `OVER([col])`, the parser will: 1. Try to match the PARTITION BY alternative 2. See the identifier but realize it's not followed by BY 3. Try the empty alternative 4. Fail because `[col]` is present when nothing was expected 5. Generate an error ## Files Modified - `SqlScriptDom/Parser/TSql/TSql160.g` - Added `overClauseBeginningNoWindowName` rule and updated `overClauseNoOrderBy` - `SqlScriptDom/Parser/TSql/TSql170.g` - Same changes as TSql160.g - `SqlScriptDom/Parser/TSql/TSql180.g` - Same changes as TSql180.g - `Test/SqlDom/ParserErrorsTests.cs` - Added `InvalidOverClauseNegative...
Adding release notes for 180.18.1 ---- #### AI description (iteration 1) #### PR Classification Documentation update adding release notes for version 180.18.1 of Microsoft.SqlServer.TransactSql.ScriptDom. #### PR Summary This pull request adds comprehensive release notes for version 180.18.1, documenting bug fixes, dependency updates, and changes to the SQL script generator. - `/release-notes/180/180.18.1.md`: Documents platform support for .NET Framework 4.7.2, .NET 8, and .NET Standard 2.0+ - `/release-notes/180/180.18.1.md`: Lists five parser bug fixes including TRIM clause parsing, DATEADD/DATEDIFF/DATEPART function argument handling, and OVER clause validation - `/release-notes/180/180.18.1.md`: Notes .NET SDK update to version 8.0.420 and script generator improvement for semicolon placement before trailing comments <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
dzsquared
approved these changes
May 1, 2026
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.
Sync repos: Release 180.18.1