Skip to content

Sync repos: Release 180.18.1#204

Merged
llali merged 3 commits intomainfrom
dev/llali/sync050126
May 1, 2026
Merged

Sync repos: Release 180.18.1#204
llali merged 3 commits intomainfrom
dev/llali/sync050126

Conversation

@llali
Copy link
Copy Markdown
Member

@llali llali commented May 1, 2026

Sync repos: Release 180.18.1

Dependabot and others added 3 commits May 1, 2026 12:04
…]) 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&#39;t followed by the `BY` keyword:

```antlr
overClauseBeginningNoWindowName:
    OVER LeftParenthesis
    (
        Identifier { Match(&quot;PARTITION&quot;) } 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&#39;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 -->
@llali llali merged commit b317381 into main May 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants