Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Supabase 13 min read Deep dive mediumAdept

Postgres Language Server: Initial Release

Postgres Language Server is an LSP implementation for Postgres offering autocompletion, syntax error highlighting, type-checking via PREPARE/EXPLAIN against a live database, and a Squawk-inspired linter, available for VSCode, Neovim and as a CLI. Its architecture treats each SQL statement as an independent compilation unit with the database schema as the source of truth. A custom Pratt-parser statement splitter falls back to semicolons and double newlines. libpg_query handles precise parsing of valid SQL, while tree-sitter covers incomplete input for autocompletion. On edits, only changed statements are invalidated and later statements just have their ranges shifted, so cached ASTs survive. Completions are scored from a lazily loaded in-memory schema cache, so no database query is needed per keystroke.

Assumes: Language Server Protocol basicsSQL and Postgresparsers and syntax trees

Related posts

  • Postgres Language Server: implementing the Parser

    Supabase hardMaster

    A Postgres language server's parser builds on libpg_query rather than a custom grammar, and has to work around two gaps in it. To tolerate syntax errors, a resilient LL source parser splits input into statements by their distinct leading keywords and parses each one independently. Because libpg_query exposes only an AST with incomplete or misleading location data, the CST is reverse-engineered by matching scanned tokens (plus regex-extracted whitespace) to node properties, using a breadth-first search over the tree. Rust procedural macros generate the location, property and tree-walking code from libpg_query's protobuf definitions, which removes most of the manual match-statement boilerplate.

  • We're building Postgres in Rust. Using the LLVM of databases

    Turso easyNovice

    Turso, a Rust rewrite of SQLite, is adding a Postgres frontend by parsing Postgres SQL into a common AST and compiling it to Turso's VDBE bytecode, turning the engine into an "LLVM of databases" with pluggable frontends. The argument is that SQL databases differ mostly in on-disk layout, not in core operations, so Postgres semantics can be expressed in or added to the VDBE. A C-to-VDBE compiler running Doom illustrates that the bytecode works as a real VM. The work starts from the earlier pgmicro experiment and is early-stage but runnable from source. Planned pieces include the Postgres wire protocol, embedded and in-browser use, live materialized views, and WASM-sandboxed extensions, aiming for broad rather than 100% compatibility.

  • dbdev: PostgreSQL Package Manager

    Supabase mediumAdept

    database.dev (dbdev) is a read-only preview of a package manager for PostgreSQL, playing the role npm or cargo play for other languages. It installs SQL packages as native Postgres extensions via pg_tle and pgsql-http, so they work on hosted platforms without filesystem access. On top of Postgres's own extension rules it enforces major.minor.patch semver and namespaces packages by publisher handle to prevent name and typo squatting. Example packages include an index advisor built on hypopg, PostgREST header tooling and a LangChain hybrid-search backend; the main limitation is that packages must be Trusted Language Extensions, a gap pl/rust narrows.

  • Bringing psql’s \d to your web browser

    Neon mediumAdept

    Neon's web SQL Editor now supports psql backslash introspection commands like \d, \l, \dx and \sf, which live in psql's C client code rather than the Postgres server. Instead of compiling psql to WASM with emscripten, the C was translated to JavaScript via RegExp search-and-replace, reimplementations of helpers like sprintf, and a test script comparing output against real psql until every command matched; most fixes involved pointer arithmetic. Because backslash commands must be handled separately, SQL is now split client-side with a small open-source lexer using sticky RegExps that understands quoted identifiers, nested comments, escape and dollar-quoted strings, so only significant semicolons terminate statements.

  • What To Know About Postgres if You’re Coming From SQL Server

    Neon mediumAdept

    Postgres and SQL Server share SQL but differ in dialect details that trip up migrating developers. Identifiers are quoted with double quotes instead of square brackets. GETDATE/DATEADD/DATEDIFF become CURRENT_TIMESTAMP, interval arithmetic and date subtraction, and TOP becomes LIMIT/OFFSET. Strings concatenate with || rather than +, CROSS APPLY becomes CROSS JOIN LATERAL, and string comparison is case-sensitive by default. Beyond syntax, Postgres is community-driven, so features like UUID generation or trigram search arrive as extensions, and tooling and hosting choices are open rather than vendor-defined.

The quest for software engineering knowledge.

Look:
Layout: