You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, great work. I'm long searching for a proper T-SQL parser. I like your approach with Go. However, I tried some of my typical workloads and I wonder weather they are in scope for the package. Today with require github.com/ajitpratap0/GoSQLX v1.16.0 I get a lot of parse errors for batches that do run in production. Can you comment on your plans, please?
To illustrate, here is some synthetic sql. Every line starting with a comment raises an error similar to 2026/10/24 01:14:29 gosqlx: syntax error: Error E2002 at line 2, column 5: expected statement, got IDENTIFIER. Especially this fails:
DECLARE a variable
IF BEGIN .. END ELSE BEGIN ... END and probably other control structures
RAISERROR() WITh NOWAIT
BEGIN TRAN and COMMIT / ROLLBACK
selecting from table valued functions
maybe also SELECT ... CROSS APPLY dbo.TVF(...)
The idea is that the parsing succeeds after all -- were removed. It won't do anything proper, of course, but it is plain T-SQL syntax.
Thanks,
Martin
package main
import (
"fmt""log""github.com/ajitpratap0/GoSQLX/pkg/gosqlx""github.com/ajitpratap0/GoSQLX/pkg/sql/keywords"
)
funcmain() {
// Parse SQL in one line - that's it!ast, err:=gosqlx.ParseWithDialect(` -- BEGIN TRANSACTION; -- DECLARE @myVar INT = 10; -- IF @myVar > 5 BEGIN SELECT a = A , b as [B plus] , c = @myVar , d = NULL , e = (select top 1 name from dbo.users where active = 1) FROM dbo.users WITH (NOLOCK) WHERE active = true ;WITH cte AS ( SELECT id, name FROM dbo.users WHERE active = 1 ), cte2 AS ( SELECT id, name FROM dbo.users WHERE active = 2 ) SELECT o.*, cte.*, cte2.name as cte2_name FROM cte left outer join dbo.orders o on cte.id = o.user_id left join cte2 on cte.id = cte2.id ; -- END ELSE BEGIN INSERT INTO users (name, email) VALUES ('Jane Roe', 'jane.roe@example.com'), ('Jamie Roe', 'jamie.roe@example.com'); -- END -- RAISERROR('This is test message #7 severity 0', 0, 7) WITH NOWAIT; -- select 1 from dbo.TableValuedFunction('p1', 2, -5); -- ROLLBACK; `, keywords.DialectSQLServer)
iferr!=nil {
log.Fatal(err)
}
fmt.Printf("Successfully parsed SQL!\n")
fmt.Printf("Type: %T\n", ast)
fmt.Printf("Statements: %d\n", len(ast.Statements))
fori, stmt:=rangeast.Statements {
fmt.Printf("Statement %d: %v\n", i+1, stmt.TokenLiteral())
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Hi, great work. I'm long searching for a proper T-SQL parser. I like your approach with Go. However, I tried some of my typical workloads and I wonder weather they are in scope for the package. Today with
require github.com/ajitpratap0/GoSQLX v1.16.0I get a lot of parse errors for batches that do run in production. Can you comment on your plans, please?To illustrate, here is some synthetic sql. Every line starting with a comment raises an error similar to
2026/10/24 01:14:29 gosqlx: syntax error: Error E2002 at line 2, column 5: expected statement, got IDENTIFIER. Especially this fails:DECLAREa variableIF BEGIN .. END ELSE BEGIN ... ENDand probably other control structuresRAISERROR() WITh NOWAITBEGIN TRANandCOMMIT/ROLLBACKSELECT ... CROSS APPLY dbo.TVF(...)The idea is that the parsing succeeds after all
--were removed. It won't do anything proper, of course, but it is plain T-SQL syntax.Thanks,
Martin
All reactions