SQLTy vs sqlglot¶
Both parse SQL and infer the type of each expression from a schema, with no database.
sqlglot is a Python library: a parser, optimizer and
transpiler for 33 dialects, whose annotate_types labels each expression with a SQL type.
SQLTy is a checker: it finds the queries in your code, infers their Python row types and
parameters, and reports mismatches. SQLTy runs sqlglot's own type tests to find its gaps.
Quick comparison¶
| sqlglot 30.36 | SQLTy 0.10 | |
|---|---|---|
| What it is | A library you call | A CLI, language server and type checker |
| Output | SQL types on an AST (DOUBLE, ARRAY<STRING>) |
Python types (float, list[str], X \| None) and diagnostics |
| Nullability | Not tracked | Inferred through joins, filters and expressions |
| Finds queries in code | No: you pass it SQL | Yes: strings in Python, .sql files |
| Transpiles between dialects | Yes, its main feature | No |
| Dialects | 33 | PostgreSQL, MySQL, SQLite; DuckDB and others best effort |
| Written in | Python (optional compiled tokenizer) | Rust |
On sqlglot's annotate_types and annotate_functions fixtures, 223 expressions get the same
type, 6 differ and 49 are left untyped by SQLTy (98 have no Python equivalent). All the
differences are decimal literals, which sqlglot reads as DOUBLE and PostgreSQL as numeric,
plus ALL(SELECT 1). The gaps are functions that none of PostgreSQL, MySQL and SQLite has,
such as SORT_ARRAY.
Where SQLTy is stronger¶
- A complete check, not a building block. It finds queries, compares row types and reports in your editor and CI.
- Python types and nullability, which is what your type checker needs.
- Rules such as fan-out aggregates and migration safety.
Where sqlglot is stronger¶
- Transpiling, optimizing and lineage. It rewrites SQL between dialects, which SQLTy doesn't do.
- Dialect breadth, especially warehouse dialects such as BigQuery, Snowflake and Spark.
- A Python API for building your own tools.
Which should you choose?¶
Choose sqlglot to transform, transpile or analyze SQL programmatically. Choose SQLTy to check that the queries in an application match its schema and its code. They don't overlap much.
What SQLTy is missing¶
- Warehouse functions outside PostgreSQL, MySQL and SQLite, such as
SORT_ARRAYandTIME_ADD. - Transpiling, by design.
Common questions¶
Does SQLTy use sqlglot?¶
Not to check your code: SQLTy's engine is written in Rust. Its compatibility report runs sqlglot's type fixtures to find what SQLTy doesn't type yet.
Sources¶
- sqlglot 30.36.0,
annotate_types.sqlandannotate_functions.sqlfixtures scripts/compat/reports/sqlglot.mdin the SQLTy repository (regenerated weekly)