Skip to content

PostgreSQL

@typed-sql/postgres contains the PostgreSQL grammar, catalog model, resolver, type policy, and runtime codecs. The optional @typed-sql/postgres/pg entrypoint loads the pg driver installed by your application.

Public entrypoints

  • @typed-sql/postgressql, dialect factory, default type policy, analysis, and type mapping.
  • @typed-sql/postgres/runtime — driver-neutral rendering and codec utilities.
  • @typed-sql/postgres/pg — schema provider and executable database adapter for application-owned pg.

Supported SQL

SurfaceBehavior
Static tagged templatesRecognizes imports and aliases from @typed-sql/postgres.
SELECT, DISTINCT, DISTINCT ONInfers static row shapes.
Tables, schemas, aliases, and starsResolves catalog names, ambiguity, and USING column merging.
Inner and outer joinsPropagates outer-join nullability.
CTEs and derived, correlated, or scalar subqueriesValidates unsafe scalar and IN arity.
Grouping, aggregates, and windowsCovers common aggregates, FILTER, and named or inline windows.
Expressions, CASE, casts, and parametersInfers parameters from columns, casts, DML targets, ranges, limits, and catalog functions.
Arrays, enums, domains, JSON, and catalog functionsResolves known types and function name or arity.
INSERT, UPDATE, DELETE, RETURNINGCommands without RETURNING infer Query<never, Parameters>.

Set operations and WITHIN GROUP are not supported. Dynamic identifiers receive no static inference; use sql.ident() explicitly.

Unsupported, ambiguous, or version-gated SQL produces a diagnostic or conservative unknown. It does not receive an optimistic row type.

Introspection

The provider records tables, views, columns, defaults, server version, arrays, enums, domains, and user functions for the configured schemas. Generated snapshots include grammar, catalog, and type-policy hashes.

Runtime behavior

The adapter installs parsers per query and does not mutate pg.types. Policy-controlled OIDs are decoded by typed-sql; other OIDs delegate to the installed driver's parser table. Driver settings that would contradict the selected type policy are rejected.

See Database type mappings and Compatibility.

Released under the MIT License.