February 17, 2026
Type Wars: SQL Edition
Show HN: Pg-typesafe – Strongly typed queries for PostgreSQL and TypeScript
New SQL typing tool drops; HN erupts with “Just use Drizzle” vs “how’s this different?”
TLDR: pg-typesafe reads your SQL and auto-generates TypeScript types for Postgres without runtime overhead. The community split fast: comparisons to Kysely, sqlc, and Drizzle vs curiosity about [porsager/postgres] support; it matters because safer, predictable data in code means fewer bugs and faster shipping for developers.
Another day, another promise to make databases less scary: pg-typesafe says it auto-writes TypeScript types from your plain SQL, with zero runtime baggage and no extra code clutter. Translation: you write a normal database query, and your editor knows exactly what comes back—no guesswork. But the crowd? Spicy. The top chorus is basically, “Cool… but how is this different from the other dozen tools?” with folks name-dropping Kysely + codegen, sqlc’s TypeScript generator, and the ever-present “Just use Drizzle” mic drop. Haskell fans even rolled in like historians, linking postgresql-typed to say this idea’s been around.
There’s genuine curiosity too: one dev asked if it plays nice with porsager/postgres, hinting at a dream setup where types are derived automatically instead of manually validating with Zod (a schema checker). The limitations—works best with fixed, non-dynamic queries—sparked quiet side-eye, but also nods from the “constant SQL is safer anyway” crowd. Meanwhile, recipes for handling big number types and fancy JSON columns got a few “nice touch” reactions. In short: pg-typesafe enters the Type Wars arena with a clean, minimal pitch, and the comments instantly turned into a sequel of the ORM (database toolkit) debate, memes and all.
Key Points
- •pg-typesafe generates TypeScript types for PostgreSQL queries without runtime dependencies or added query verbosity.
- •Initial setup creates src/defs.gen.ts and requires casting the pg Pool to the generated TypesafePool to enable typed queries.
- •The tool only analyzes constant SQL strings; dynamic queries are not supported for typing.
- •CLI options include connectionString, definitionsFile, tsConfigFile, and configFile, with a defineConfig-based pg-typesafe.config.ts.
- •Recipes show mapping PostgreSQL BIGINT to JavaScript bigint and contextual typing for JSONB columns; type propagation uses Typesafe* interfaces.