Skip to content

v0.10.0

Latest

Choose a tag to compare

@jirikuncar jirikuncar released this 01 Dec 20:25
Immutable release. Only release title and notes can be modified.
65c53b7

sqlty 0.10.0 checks typed raw SQL in Go under go vet, checks and types rustmy and asyncpg calls, and adds rules for NULL writes, UPDATE and DELETE without WHERE, argument counts, duplicate output columns and repeated parameters. The language server gains completion of functions, keywords and enum values, signature help, go to definition and semantic tokens.

pip install -U sqlty                       # or: uv add sqlty@latest
brew install jirikuncar/sqlty/sqlty        # the native executable
brew install jirikuncar/sqlty/sqlty-vet    # the go vet tool
npx @sqlty/cli check                       # the native executable, from npm

Upgrading

  • New errors can fail a check that passed on 0.9.0 (all error by default):
    • null-write: a literal NULL written to a NOT NULL column, in INSERT, UPDATE, ON CONFLICT DO UPDATE and MERGE. PostgreSQL only; a table with a BEFORE row trigger is skipped (#1534)
    • argument-count-mismatch: a built-in called with an argument count that fits none of its overloads, and * passed to a function other than count. Reported at the function name. Functions the schema defines, named arguments and table functions are not checked (#1434, #1558, #1671)
    • duplicate-column: a query read into a row mapped by name (TypedDict, dataclass, Pydantic, Protocol, dict) with two columns of one name. Alias one: p.id AS p_id (#1529)
    • set-column-count: a UNION, INTERSECT or EXCEPT branch with another column count than the first (#1415)
    • position-out-of-range: an ORDER BY or GROUP BY position that names no select item (#1418)
    • column-alias-count: an alias list longer than the relation it renames, or shorter on MySQL and SQLite CTEs (#1424)
    • rejected-query for a parameter used twice with types of different categories, which PostgreSQL rejects: id = %(x)s OR name = %(x)s. SQLite reports nothing (#1557)
    • unknown-table for a qualifier that names no FROM item: SELECT users.id FROM orgs and SELECT users.id FROM users AS u (#1398)
    • param-type-mismatch for a str literal argument that PostgreSQL's input function for the parameter's type rejects ("abc" for an integer, "2026-02-30" for a date) and for an enum or CHECK (col IN (...)) parameter given a value the column never holds (#1403)
    • params-type-mismatch and param-type-mismatch now also judge parameters of a CHAR(n) column whose CHECK values are shorter than n; trailing spaces of both sides are ignored, as the server does (#1707, #1710)
    • ungrouped-column now judges SELECT * over JOIN ... USING and NATURAL JOIN with GROUP BY. A GROUP BY position with * is no longer judged (#1701)
    • position-out-of-range makes ungrouped-column silent for that position (#1418)
    • json-shape-mismatch now checks the field types of a Pydantic model, not only its keys, with the conversions Pydantic performs: a lax field takes a JSON string for any scalar and a JSON integer for bool, a strict field (strict config, Field(strict=True), Strict* types) keeps the TypedDict rules. A number into str or an array into a scalar is reported (#1726)
  • New warnings where 0.9.0 was silent:
    • missing-where: UPDATE or DELETE without WHERE, in queries and .sql query files. WHERE true means it. Migrations keep unbatched-backfill (#1517)
    • nullable-write: a value that can be NULL, such as a nullable column or a LEFT JOIN column, written to a NOT NULL column. PostgreSQL only (#1534)
    • unused-cte: a CTE nothing reads. Editors fade it (#1422)
    • unknown-function for a table function in FROM that is neither built in nor defined by the schema, with a check --fix suggestion (#1436)
    • fanout-aggregate and unproven-join now see the key of a derived table with its own WITH, so joins to it are judged where they were skipped (#1691)
  • rewrite writes different parameter types than on 0.9.0, so your next rewrite changes them:
    • a cast parameter takes the cast type: %s::int is int | None instead of typing.Any (#1557)
    • in a module with from datetime import datetime, parameter types read datetime, not datetime.datetime, and a class the module lacks is imported by name (#1505)
  • A CHAR(n) column whose CHECK values all have n characters is Literal[...] instead of str: CHAR(1) CHECK (c IN ('Y', 'N')) is Literal['Y', 'N']. A shorter value keeps str. literal-write and unmatched-literal ignore trailing spaces on PostgreSQL (#1546)
  • Types that changed to follow the server:
    • PostgreSQL: a subscript of text[][] is text, as the server types it (#1399)
    • MySQL: an integer literal above BIGINT UNSIGNED is Decimal; JSON_TABLE columns under NESTED PATH are nullable (#1634); GROUP_CONCAT and string functions of BIT or binary values return bytes; BIGINT UNSIGNED with an integer literal is DECIMAL; TIMESTAMP with a string literal is a string; CAST(bytes AS CHAR) can be NULL (#1581, #1585)
    • driver = "asyncpg" types json/jsonb as str, bit/varbit as asyncpg.BitString, geometric types as asyncpg.Point and the like, ranges as asyncpg.Range[T]; a [tool.sqlty.types] entry for a SQL type now applies to every result value of that type, not only columns (#1416)
  • A qualified column alias list on a table, view or CTE renames its columns, as on PostgreSQL and DuckDB: SELECT id FROM users AS u(a) is now unknown-column (#1495)
  • sqlty check now reads \N{name} escapes in query strings as Python does (#1401)

Go

Typed raw SQL for Go, checked in go vet and golangci-lint with no generated code and no database (preview) (#1498).

  • sqlty.SQL[R, P], NoParams and NoRows in the module github.com/jirikuncar/sqlty/go; pgxq runs them through pgx v5 (All, One, Exec, Each, QueueAll, QueueOne, QueueExec)
  • sqlty-vet applies the SQL rules of sqlty check with your [rules] severities, checks row struct fields as pgx.RowToStructByName matches them, nullability, the Go types pgx scans, and the arguments of pgxq calls and of pgx's Query, QueryRow, Exec and Batch.Queue given string(q). 74 µs per query in the analyzer, 100 ms for a package of 1,000 queries
  • Linux (glibc 2.35 or newer, not Alpine) and macOS; no Windows build yet
  • GitHub Action jirikuncar/sqlty/go@vX.Y.Z runs go vet and annotates each finding
  • Diagnostics carry go/analysis suggested fixes: nullable-mismatch turns a field into a pointer, redundant-optional removes it, and unknown-column and unknown-table replace the name in the query literal. A field changes only when nothing else can read it (#1712)
  • brew install jirikuncar/sqlty/sqlty-vet installs the tool alone; the sqlty formula ships only sqlty (#1666)
  • A Go example in the playground (#1665); comparison pages for pggen, Bob, go-jet, scany/sqlx and sqlvet (#1553)

ESLint/TypeScript

  • sqlty/check-sql accepts a named row type: sql<User[]> is no longer reported as a mismatch, and eslint --fix no longer inlines the literal, when User has exactly the row's shape (#1657)
  • duplicate-column is reported for every query. A fieldTransform that maps two columns to one key is reported and gets no row type (#1529)
  • @sqlty/wasm answers one bare SQL query with op: "query": columns, parameters and diagnostics (#1390)

Drivers

  • rustmy: sqlty check checks the parameters of execute and executemany on connections, cursors and pools from rustmy.connect, rustmy.aio.connect, rustmy.Pool and aio.create_pool, with param-count-mismatch, param-type-mismatch and extra-param (#1484). sqlty.drivers.rustmy (extra sqlty[rustmy]) has typed execute, execute_async, scalar and scalar_async, blocking and async (#1485); example project examples/09_rustmy (#1486)
  • asyncpg: values typed as asyncpg loads them (see Upgrading) (#1416); .acquire() on an asyncpg pool is followed (#1484)
  • psycopg: calls on a subscripted annotation, conn: Connection[tuple[object, ...]], AsyncConnection[...], Cursor[...] and aliases of them, are checked (#1506)

Checks

  • Repeated parameters: a named parameter or $1 used more than once takes the type of its first typed use in every dialect (#1557)
  • SQLite function signatures from the SQLite documentation, so SQLite gets hover, signature help and argument-count-mismatch (#1558)
  • Function argument counts follow the databases, including optional parameters and overloads the PostgreSQL docs omit (#1433)
  • unknown-table suggests the closest table, view or CTE, and check --fix replaces the name (#1414); unknown-column in an unaliased subquery says "in the subquery" (#1400)
  • ambiguous-column and duplicate-alias point at related locations: the FROM items that have the column and the earlier use of the alias (#1404)
  • Extension types and functions, gated by CREATE EXTENSION: hstore (#1429), pg_trgm, fuzzystrmatch and pgcrypto (#1430), ltree and intarray (#1432), pgvector vector, halfvec and sparsevec with distances (#1435)
  • A SQLite CTE may read a later CTE of its WITH; PostgreSQL, MySQL and DuckDB still report it (#1500)
  • CHECK constraints are tracked by name, so ALTER TABLE ... DROP CONSTRAINT clears only the values and discriminators of the constraint it names (#1684)
  • LIKE columns of CREATE TABLE stand where the LIKE is written (#1397)
  • A PostgreSQL operator right after ), as in (id + 1)*2 and (id, name)=(1, 'a'), parses (#1619)
  • Diagnostics of PostgreSQL queries with ? placeholders keep their spans, so check underlines the name and --fix can write (#1686)
  • SELECT '%s' no longer types as Literal['$0']; a %s inside a string literal or comment is left unbound (#1714)
  • Python reading: nested format specs in f-strings, aliased dataclass decorators, tuple[T, ...] as a variable-length tuple, Literal[-1], and from typing import * (#1631)
  • A schema ** glob stops at a linked directory it is already inside, instead of walking links to 64 levels, and no longer drops files of trees deeper than 64 levels (#1699)
  • -- sqlty: ignore[rule without ] is a bare ignore at any line ending (#1669)
  • A helper call spelled with compatibility characters, such as fullwidth fetch_all(...), is read in NFKC form as Python reads it, so its query is checked (#1721)

Editor and language server

  • Completion:
    • function names, with the schema's functions first, then the dialect's built-ins (#1431), and table functions in FROM (#1437)
    • keywords and clause skeletons that fit the cursor (#1528)
    • ORDER BY and GROUP BY aliases and positions (#1531)
    • enum labels and CHECK values inside string literals compared with or written to the column (#1541)
    • columns of every table before the query has a FROM (#1439); FROM lists the relations that have the selected columns first (#1440); column names match as a subsequence, so uid finds user_id (#1442)
    • schema comments from COMMENT ON in hover and completion, PostgreSQL and DuckDB (#1421)
    • the case of a quoted schema qualifier is kept (#1395); names a schema hides no longer use up the completion limit (#1675)
  • Signature help for PostgreSQL (745 overloads), DuckDB, MySQL (402 overloads) and SQLite built-ins, in the server, VS Code and the playground; signatureHelp.enable = false turns it off (#1425, #1426, #1427, #1428, #1558)
  • Go to definition of tables, views and columns to the schema statement that defines them (#1419, #1420), and of CTE and subquery columns, ORDER BY and GROUP BY aliases and positions to the select item (#1423)
  • VS Code colors SQL in strings marked --sql in TypeScript, JavaScript, Rust and Go files; highlighting only (#1723)
  • Semantic tokens: names colored by what they resolve to (table, view, schema, alias, column, type, deprecated column) (#1441), function names (#1438), every statement of a query, multi-word types and enum members (#1483), ranges and .sql query files (#1456)
  • A client that declares completionList.itemDefaults with editRange, such as VS Code, gets the edit range once per list. Server CPU for a completion of a table name with 400 tables and 200 items: 1653 to 1107 µs (#1630)

Playground

  • Completion, hover and signature help inside sql templates of the TypeScript example (#1587)
  • Go quick fixes and "Fix All in File" (#1712)

CLI

  • sqlty check reads each walked directory's configuration once, and a file no override matches shares its settings (#1384, #1637)
  • The Agent Skills ship in the PyPI and npm packages at .agents/skills/, where uvx library-skills --claude and npx library-skills find them (#1457)

Performance

  • Parsing schemas and preparing modules run in parallel. On projects of 5,000 and 20,000 tables wall time falls 54 % and 55 % (mimalloc), at 15 to 17 % more CPU; on the synthetic ci project at 4x it falls 14 % (#1358)
  • Costly neighbouring modules are checked on all threads. Wall time on a large project with clustered query modules falls by about a quarter at the same CPU (#1635)
  • A bound copy of a query reuses the analysis of the query as written unless an argument decides a column. On a large project, second analyses fall from 1090 to 285 and check CPU from 2661 to 2494 ms (#1638, #1715)
  • Schemas of a project's databases load in parallel, about a fifth less schema time with two databases that share a large schema (#1639). A schema that extends another's parses only its added statements: check CPU 2788 to 2696 ms, and a one-file check 233 to 173 ms (#1717)
  • The helper index and the file walk are faster: on nested projects of 3,200, 6,400, 12,800 and 25,600 modules, building the helper index went from 25, 82, 301 and 1120 ms to 7, 13, 37 and 81 ms, and the largest checks in 3829 ms instead of 4928 (#1547). The file walk takes half the time on a large tree (#1637)
  • The executable and the PyPI command skip freeing the workspace when they exit after check: about 3 % of wall time on a large project, 891 to 851 ms for the PyPI command (#1636, #1716)
  • Check and editor work is linear in query size: 2,048 CTEs check in 20 ms instead of 1 s; 4,096 WHENs on distinct columns check in 30 ms instead of 1 s and hover in 86 ms instead of 3.1 s (#1548)
  • FROM completion ranking: 5,000 tables 32.2 to 26.4 µs (#1579)

Docs

Contributors

Thanks to @Kludex for CHAR(n) parameters and CHECK values, SELECT * over JOIN USING, spans for ? placeholders, DROP CONSTRAINT by name, fan-out keys through WITH, symlink loops in schema globs, the ESLint named row type, the SUBSTRING span, the completion limit, Pydantic field types in JSON columns, NFKC helper names and --sql highlighting in other languages.

Full changelog: v0.9.0...v0.10.0