IdentifierBracketing.IncludeBrackets brackets aggregate function name in PIVOT (SUM becomes [SUM]), producing invalid T-SQL
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 67/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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)
- Ngôn ngữ chính
- GAP
- Star
- 284
- Fork
- 47
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/SqlScriptDOM
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
microsoft/SqlScriptDOM#228 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
microsoft/SqlScriptDOM#183 ·
-
Add a Multiline option for CASE expressions (WHEN/THEN/ELSE on their own lines)Có thể đã có người làm @trg-alasdair đã nhận 40 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 56/100
microsoft/SqlScriptDOM#226 · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
microsoft/SqlScriptDOM#225 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
microsoft/SqlScriptDOM#224 ·
Tất cả issue của microsoft/SqlScriptDOM
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
WalletConnect/walletconnect-monorepo#7392 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
rohit746/pdf-view.nvim#109 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Azure/azure-functions-nodejs-extensions#180 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
tidyverse/ellmer#1226 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày