IdentifierBracketing.IncludeBrackets brackets aggregate function name in PIVOT (SUM becomes [SUM]), producing invalid T-SQL
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 67/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
研究方向
Read SqlScriptGeneratorVisitor.PivotedTableReference.cs and trace how AggregateFunctionIdentifier is emitted; then inspect SqlScriptGeneratorVisitor.Identifier.cs and the casing options mentioned in the issue. Reproduce with the supplied PIVOT query and IdentifierBracketing = IncludeBrackets. Done when the aggregate name remains unbracketed and uses built-in function casing while ordinary identifiers still follow their configured behavior.
由索引模型根據 Issue 內容生成。
描述
Summary
With IdentifierBracketing.IncludeBrackets, the script generator wraps the aggregate function name inside a PIVOT clause in square brackets. The output is invalid T-SQL and fails to parse.
This shows up in SSMS 22.7+ (built-in SQL formatter with identifier_bracketing = IncludeBrackets), because the formatter is built on ScriptDOM.
Repro
Input:
SELECT [p].[2024], [p].[2025]
FROM [#chk] PIVOT (SUM([volume]) FOR [year] IN ([2024], [2025])) AS [p];
Format with IdentifierBracketing = IncludeBrackets (SSMS: Tools > Options > SQL Formatter, or identifier_bracketing = IncludeBrackets in .editorconfig).
Actual output:
... PIVOT ([SUM] ([volume]) FOR [year] IN ([2024], [2025])) AS [p];
Executing the result fails with:
Msg 102, Level 15, State 1
Incorrect syntax near '('.
Expected output: SUM stays unbracketed:
... PIVOT (SUM([volume]) FOR [year] IN ([2024], [2025])) AS [p];
Likely cause
PivotedTableReference.AggregateFunctionIdentifier is a MultiPartIdentifier, and SqlScriptGeneratorVisitor.PivotedTableReference.cs emits it with GenerateFragmentIfNotNull(node.AggregateFunctionIdentifier). That sends it through the normal identifier path in SqlScriptGeneratorVisitor.Identifier.cs, so IncludeBrackets applies to it like a column or table name.
The aggregate name should probably be exempt from bracketing. built_in_function_casing should apply to it instead of identifier_casing, so that with identifier_casing = Lowercase we don't get [sum].
Workaround
Use IdentifierBracketing.Preserve, or rewrite the PIVOT as conditional aggregation (SUM(CASE WHEN [year] = 2024 THEN [volume] END) AS [2024]).
Environment
- SSMS 22.7+ built-in SQL formatter (ScriptDOM-based)
- 主要語言
- GAP
- 星號
- 284
- 分支
- 47
- 平均合併
- 1 天 23 小時
- 30 天內合併 PR
- 3
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
microsoft/SqlScriptDOM 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 84/100
microsoft/SqlScriptDOM#228 ·
-
難度 2/5 1-3 小時 新手友好度 62/100
microsoft/SqlScriptDOM#183 ·
-
Add a Multiline option for CASE expressions (WHEN/THEN/ELSE on their own lines)可能已有人在做 @trg-alasdair 於 40 天前認領。 未關閉
難度 4/5 3-5 天 新手友好度 56/100
microsoft/SqlScriptDOM#226 · 1 個 reaction ·
-
難度 4/5 3-5 天 新手友好度 48/100
microsoft/SqlScriptDOM#225 ·
-
難度 3/5 1-2 天 新手友好度 58/100
microsoft/SqlScriptDOM#224 ·
查看 microsoft/SqlScriptDOM 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
WalletConnect/walletconnect-monorepo#7392 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 86/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
rohit746/pdf-view.nvim#109 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
Azure/azure-functions-nodejs-extensions#180 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 78/100
tidyverse/ellmer#1226 · 1 則留言 ·
維護者通常 3 天內回覆