Add MSSQL engine for parse and analyze via teesql - #4571
Merged
Conversation
Add a new mssql engine backed by github.com/sqlc-dev/teesql, a T-SQL parser producing a SqlScriptDOM-compatible AST. The engine converts teesql's AST into sqlc's internal AST and analyzes queries through the analysis core, seeded with SQL Server's type system. - internal/engine/mssql: parser, AST converter, reserved keywords and dialect seed (types, functions, operator rules) - Wire the engine into the compiler's core-analysis path and the parse and analyze commands as the mssql (alias sqlserver) dialect - Named @parameters share a number across repeated uses; OUTPUT clauses map to returning lists with INSERTED/DELETED qualifiers stripped; the dbo schema maps to the catalog's default namespace - End-to-end coverage under parse_basic, analyze_basic and analyze_params Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FrnQ4EoZ3WCWWrSsm8bhCP
Address review findings on the initial engine: - DELETE dropped its FROM clause, so the T-SQL join form (DELETE b FROM books b JOIN ...) failed to resolve. UPDATE and DELETE now resolve an alias target against the FROM clause: the matching relation becomes the statement's target, and the ON conditions of any inner join dissolved by pulling it out move to the WHERE clause. Relations under outer joins are left alone. - AST Location fields carried teesql's UTF-16 code-unit offsets while StmtLocation/StmtLen are byte offsets; the converter now maps locations through the same byte-offset table as statement spans. - Drop the unreachable "within group" reserved-keyword case: keywords are checked one identifier token at a time. - Cover INSERT ... OUTPUT and the UPDATE/DELETE alias forms end to end under analyze_dml/mssql. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FrnQ4EoZ3WCWWrSsm8bhCP
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.
Adds a new
mssqlengine backed by github.com/sqlc-dev/teesql, a T-SQL parser producing a SqlScriptDOM-compatible AST, and wires it intosqlc parseandsqlc analyze.What's included
internal/engine/mssqlparse.go— parses T-SQL via teesql and computes statement spans with a scanner aware of T-SQL string/[bracket]quoting and--//* */comments, plus a UTF-16→byte offset map (teesql mirrors ScriptDom's UTF-16 offsets).convert.go— converts teesql's AST to sqlc's internal AST:TOP,OFFSET … FETCH, DISTINCT, and UNION/EXCEPT/INTERSECTOUTPUTclauses mapped to returning lists (INSERTED/DELETEDqualifiers stripped so columns resolve against the target table)@nameparameters become numbered parameters, with repeated uses of a name sharing a numberTRY_variants, LIKE/IN/BETWEEN/EXISTS, window functionsNOT NULL,IDENTITY, and column- or table-levelPRIMARY KEYforce not-nulldboschema maps to the catalog's default namespace, sodbo.tableandtableresolve identicallydialect/— analysis-core seed: 34 SQL Server types with aliases, comparison/arithmetic/cast rules, and function signatures (count,count_big,sum/avg/min/maxoverloads, date/time functions,newid,len, string functions)reserved.go— the T-SQL reserved keyword listWiring
EngineMSSQLconfig constant; the engine always analyzes through the core (like ClickHouse and GoogleSQL, it has no legacy path)sqlc parse --dialect mssqlandsqlc analyze --dialect mssql(aliassqlserver); docs updatedTests
parse_basic/mssql,analyze_basic/mssql, andanalyze_params/mssqlwith committed goldensNotes
IN (subquery)and in OFFSET/FETCH clauses are not reported.statsas a CTE name (lexed as a keyword) — worth a follow-up fix in the teesql repo.Full test suite (
go test --tags=examples ./...) passes against live PostgreSQL and MySQL.🤖 Generated with Claude Code
https://claude.ai/code/session_01FrnQ4EoZ3WCWWrSsm8bhCP
Generated by Claude Code