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. Streaming additionally uses the application-owned pg-cursor package.

Public entrypoints ​

  • @typed-sql/postgres/profile — lightweight grammar profile for exact query-contract consumption, without the SQL analyzer or global routine catalogs.

  • @typed-sql/postgres/contract-profile — pure interpreter identities and reconciliation-owner revisions for independently checking recorded contract compatibility.

  • @typed-sql/postgres/tag — sql, renderer and runtime plan primitives without analyzer imports.

  • @typed-sql/postgres/project-catalog — selected routine metadata and its offline grammar interpreter.

  • @typed-sql/postgres/reconciliation — pure grammar-owned comparisons between native evidence and independent static claims.

  • @typed-sql/postgres/pg-contracts — explicit native query-contract acquisition over a dedicated application-owned pool.

  • @typed-sql/postgres/query — portable sql, renderer, and runtime value descriptors for buffered adapters.

  • @typed-sql/postgres — sql, runtime plan primitives, renderer and type policy.

  • @typed-sql/postgres/analysis/<major> — analyzer with one major's catalog and all maintained offline rules.

  • @typed-sql/postgres/analysis/core/<major> — the same maintained rules, with unmapped functions requesting qualified query contracts through TSQ408.

  • @typed-sql/postgres/analysis — explicit eager analyzer and compatibility exports, including schema introspection and semantic routing.

  • @typed-sql/postgres/runtime — driver-neutral rendering and codec utilities.

  • @typed-sql/postgres/pg — schema provider, executable database adapter, lazy live verifier, and structured-plan inspector for application-owned pg.

  • @typed-sql/postgres/migrations — lazy migration targets, pinned PostgreSQL catalog/history operations, script validation and qualified catalog keys; requires the application-owned pg driver and optional @typed-sql/migrations package.

Supported versions ​

The stable grammar supports PostgreSQL majors 14 through 18. Patch releases are compatible within their major. The exact release-matrix targets are 14.24, 15.19, 16.15, 17.11, and 18.6. PostgreSQL 19beta3 is a non-blocking canary and requires postgres({ versionPolicy: "canary" }); prerelease evidence does not enter the stable range or its pass score. Unlisted older or newer majors remain conservative.

POSTGRES_SUPPORT_POLICY exposes the selected major lines, matrix minors, canary identity, and deprecation rule. typed-sql announces an upstream end-of-life removal at least 90 days ahead, keeps the major through its upstream final release, and removes it no earlier than the first typed-sql minor released afterward.

Every query is resolved against normalized server evidence. A generated snapshot records the full server version, normalized major, standard_conforming_strings, effective search path, installed extension identities, catalog revision, visibility scope, schema identity, and type-policy identity. Missing or malformed evidence, an unsupported major, an unavailable versioned feature, or an incompatible lexical setting produces TSQ402–TSQ407 or conservative unknown; it never inherits the newest grammar behavior. Unqualified names follow the captured search path and current-role visibility. Prefer schema-qualified names when compilation and execution can use different roles or search paths.

Keyword and identifier rules ​

Each selected major consumes a compact keyword inventory generated from that release's pinned PostgreSQL declarations. Reservation classes and bare-label permissions distinguish ordinary identifiers, qualified names and column aliases. Quoted identifiers retain their literal identity; unquoted identifiers fold ASCII letters without folding Unicode lookalikes into built-ins. Keyword recognition does not imply support for every syntax production: unsupported forms still produce a diagnostic. Runtime tags and frozen contract consumption do not load the keyword inventory.

Selecting an offline analyzer ​

Development tooling can load one major explicitly, for example:

ts
import { postgres } from "@typed-sql/postgres/analysis/core/18";

const analyzer = postgres();
MajorFull analyzerCore analyzer
14@typed-sql/postgres/analysis/14@typed-sql/postgres/analysis/core/14
15@typed-sql/postgres/analysis/15@typed-sql/postgres/analysis/core/15
16@typed-sql/postgres/analysis/16@typed-sql/postgres/analysis/core/16
17@typed-sql/postgres/analysis/17@typed-sql/postgres/analysis/core/17
18@typed-sql/postgres/analysis/18@typed-sql/postgres/analysis/core/18
19@typed-sql/postgres/analysis/19@typed-sql/postgres/analysis/core/19

The selected analyzer requires matching major evidence in its snapshot. Entry points exist for majors 14–19; the canary still requires versionPolicy: "canary". Common expressions, maintained function rules, JSON shapes, operators and coercions stay offline. An unmapped function preserves its argument evidence and produces TSQ408; configured live analysis or explicit generation can supply a qualified exact-query contract. Ordinary offline checks do not initiate connections. Other static errors remain blocking, and native acquisition keeps its own narrower version and statement boundaries. A selected-major import does not expand native support.

All maintained PostgreSQL rules remain in the core; there is no additional compatibility pack. The generic /analysis entrypoint retains all majors and its existing diagnostics. Application queries continue importing sql from @typed-sql/postgres.

Supported SQL ​

SurfaceBehavior
Static tagged templatesRecognizes imports and aliases from @typed-sql/postgres.
SELECT, DISTINCT, DISTINCT ONInfers static row shapes and validates leftmost ORDER BY agreement.
Tables, schemas, aliases, and starsResolves catalog names, ambiguity, and USING column merging.
Inner and outer joinsPropagates outer-join nullability.
Ordinary and recursive CTEs; derived, correlated, or scalar subqueriesInfers seed/member rows, validates recursive shape, models PostgreSQL 14+ SEARCH/CYCLE generated columns conservatively, and gates unaliased derived tables to PostgreSQL 16+.
UNION, INTERSECT, and EXCEPTPreserves leftmost output names, merges row types and nullability, and diagnoses arity mismatches.
Grouping and aggregatesCovers grouping sets, ROLLUP, CUBE, functional dependencies, aggregate ordering, FILTER, and ordered/hypothetical-set aggregates.
WindowsCovers named inheritance, inline definitions, all frame units, bounds, exclusions, and built-in window nullability.
Lateral and function relationsCovers implicit/explicit lateral arguments, ROWS FROM, record definitions, null-padding, and WITH ORDINALITY.
Ordering, sampling, and paginationCovers ordering operators, TABLESAMPLE/REPEATABLE, LIMIT ALL, offsets, and FETCH variants.
Expressions, CASE, casts, and parametersInfers parameters from columns, casts, DML targets, ranges, limits, and catalog functions. Generated catalogs record canonical identities, preferred categories, every direct cast among shipped core types for PostgreSQL 14–18, versioned additions and removals, and PostgreSQL's automatic string I/O conversion rules. PostgreSQL interval literals preserve optional precision and the valid single-field or field-range qualifiers while resolving to the canonical interval type. Scalar and row-valued IN lists and subqueries validate equality operators, row arity, and per-position parameter types. Quantified array/subquery and row comparisons use element-wise operator selection. COLLATE preserves collatable string types, while AT TIME ZONE selects the exact timestamp, timestamp-with-time-zone, or time-with-time-zone conversion signature and validates text or interval zones. PostgreSQL 17+ AT LOCAL applies the corresponding session-zone conversion. Exact numeric promotion, mathematical prefix, bit shift, concatenation, money, pg_lsn, unary numeric, bitwise, geometric, and asymmetric temporal arithmetic operators use fail-closed candidate selection.
Arrays, enums, domains, composites, JSON, and catalog functionsSelects typed operator and snapshot-routine candidates using exact and implicit-cast matches. Resolves array subscripts and slices, snapshot-backed parenthesized composite field selection and field-wise composite comparisons, named, defaulted, and variadic calls, array/range/enum relationships, range and multirange operators, network address operators, geometric transformation, position, intersection, distance, containment, and relationship operators, full-text composition and matching, JSON/JSONB/JSONPATH typed literals, JSON-path predicates and deletion, and all jsonb_path_* scalar and set-returning signatures. The anyelement and anycompatible polymorphic families resolve from grammar-owned evidence; unresolved or ambiguous candidates fail closed.
SQL/JSON expressions and row sourcesPostgreSQL 16+ JSON_OBJECT and JSON_ARRAY own standard key/value, query, null-handling, uniqueness, input-format, and RETURNING clauses while preserving legacy json_object(...) function calls. Constructor keys must be non-null scalar values; formatted inputs and outputs validate JSON-compatible types and UTF-8 encoding. PostgreSQL 16+ JSON_OBJECTAGG and JSON_ARRAYAGG additionally own aggregate null handling, uniqueness, input ordering, FILTER, OVER, output formats, grouping checks, parameter inference, and nullable empty-input results. PostgreSQL 16+ IS JSON validates value, scalar, array, object, and unique-key constraints for JSON-compatible string, binary, json, and jsonb inputs while preserving SQL-null propagation. PostgreSQL 17+ JSON, JSON_SCALAR, and JSON_SERIALIZE resolve JSON parsing, scalar conversion, string or binary serialization, null propagation, uniqueness, formats, encodings, and return types; the overlapping pre-17 functional json(...) cast remains version-aware. PostgreSQL 17+ JSON_EXISTS, JSON_QUERY, and JSON_VALUE own their context, path, PASSING, FORMAT JSON, encoding, and error-behavior syntax. JSON_QUERY additionally resolves JSON wrappers and quote behavior; JSON_QUERY and JSON_VALUE resolve RETURNING, constant ON EMPTY and ON ERROR defaults, and output nullability. JSON_VALUE maps JSON null to nullable SQL output and rejects collection fallbacks or formatted returns. JSON_TABLE owns its row-source grammar, constant root and column paths, path names, passing variables, ordinality, scalar, formatted, EXISTS, and recursively nested columns, output alias lists, and top-level error behavior. It flattens nested output columns, applies nested null-padding, resolves declared types and boolean coercions, and participates in implicit lateral scope. These forms infer parameters where PostgreSQL provides type context and fail closed on invalid behavior or type combinations. Older servers and missing server-version evidence produce version diagnostics.
INSERT, UPDATE, DELETE, MERGE, RETURNINGCovers identity overriding, snapshot-backed expression and partial-index conflict targets, action-scoped excluded, row/subquery assignments, comma and joined update/delete sources, positioned WHERE CURRENT OF writes, source-type validation, PostgreSQL 15+ MERGE, PostgreSQL 17+ merge returning and explicit by-target/by-source actions, and PostgreSQL 18 old/new rows and aliases. Commands without RETURNING infer Query<never, Parameters>.

Dynamic identifiers receive no static inference; use sql.ident() explicitly.

Expression collation preserves exact built-in string types. Catalog-wide validation of collation names remains conservative when the schema snapshot does not carry collation inventory evidence.

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, materialized views, foreign tables, partition parents and strategies, columns, defaults, constraints, indexes, arrays, enums, domains, composites, ranges, multiranges, and user routines for the configured schemas. Routine evidence includes argument names, modes, defaults, polymorphic family, volatility, strictness, parallel safety, and scalar, set, record, table, or command results. Server evidence records the exact server version, installed extension identities, standard_conforming_strings, search path, and the fact that catalog visibility is scoped to the current database role without storing the role name. Generated snapshots include grammar, catalog, type-policy, normalized capability, and explicit introspection scope evidence.

Stable resolution covers the documented PostgreSQL major range. Canary testing is explicit: postgres({ versionPolicy: "canary" }) selects the grammar-owned canary major; prerelease text never satisfies the stable range accidentally.

Extension manifests ​

definePostgresExtensionManifest() declares an extension name, an exact installed-version list, and a reviewable manifest revision. Active manifests may contribute snapshot-v2 types and routines, unary or binary operator signatures, cast contexts, runtime codecs, and an optional driver-neutral introspection callback. Pass manifests to postgres({ extensions }) for analysis and to PostgresSchemaProvider({ extensionManifests }) when their introspection callbacks should augment a generated snapshot.

Manifests activate only when the snapshot records a matching installed extension version. Unknown extensions remain conservative. Unsupported versions produce TSQ403; conflicting type, routine, operator, cast, or codec declarations produce TSQ407 and make query semantics unknown. Codec and introspection callbacks receive typed-sql's driver-neutral contracts, so importing the default PostgreSQL entrypoint does not load pg or another database driver.

For execution, pass the generated snapshot path as compatibilitySnapshot and the same manifests as extensionManifests to createPgDatabase(). The adapter resolves each active codec's database type to connection-local scalar and array OIDs, then installs those decoders per query. The generated file remains a compiler artifact referenced by path; application modules do not import APIs from it.

createPgLiveVerifier() sends PostgreSQL Parse and Describe protocol messages without Bind or Execute, so every supported major supplies parameter OIDs and result-column OIDs without receiving application values. The verifier resolves those OIDs through pg_type, then deallocates the named statement. See Live verification.

createPgPlanInspector() uses JSON EXPLAIN without ANALYZE. PostgreSQL 16 and newer use GENERIC_PLAN; PostgreSQL 14 and 15 force a generic prepared plan in a rolled-back transaction. Neither path needs parameter values. Optional transient samples request a custom plan. Normalized evidence excludes expressions and literals. See Query plan governance.

createPostgresRoutedDatabase() composes application-owned databases and parses runtime query shapes with the PostgreSQL grammar. Stable, non-locking reads may use a supplied replica. FOR UPDATE, FOR NO KEY UPDATE, FOR SHARE, FOR KEY SHARE, writes, volatile functions, session state, and unknown statements use primary. isPostgresRetryableTransactionError() recognizes only transaction rollback SQLSTATE 40001 and deadlock SQLSTATE 40P01. See Route reads and retry transactions.

Migration execution ​

createPgMigrationTarget() supplies the PostgreSQL execution service for the migration CLI. It uses a pinned connection for advisory locking, transactional SQL, history and checks, and compares independently replayed schema evidence before new migrations. Manual additions block execution until explicitly reconciled; refreshing an application snapshot does not accept that drift. The guide covers fresh databases, global and migration-local checks, schema-only reconciliation, baseline adoption and inspected recovery.

Migration catalog capture requires PostgreSQL 14 or newer; the repository's live migration suite exercises PostgreSQL 18.6. Choose an explicit expected database identity, a managed namespace scope and a separate empty replay database. The adapter never provisions or resets databases. Importing the default grammar does not load the migration package or a driver.

Runtime behavior ​

The adapter installs parsers per query and does not mutate pg.types. Boolean, integer, floating, bigint, numeric, temporal, JSON, bytea, and their supported arrays use typed-sql's codec policy; enums remain strings, domains retain their base representation, and types without a typed-sql or manifest codec delegate to the installed driver's parser table. bytea is normalized to Uint8Array. Driver settings that would contradict the selected type policy are rejected.

For queries with executable value metadata, the owned pg adapter preserves JSON and JSON-array wire text until the shared validator decodes it. This keeps SQL NULL distinct from JSON null, including native SQL array elements. Untransformed queries retain the selected legacy JSON policy. Custom pools may declare rawJsonParsers: true only when they honor query-local text parsers; already parsed transports reject contracts whose null distinction cannot be verified.

When compatibilitySnapshot is present, createPgDatabase() reads that generated artifact and negotiates the target before returning. It rejects mismatched grammar versions, server majors, extension versions, lexical settings, search paths, built-in catalog revisions, schema identities, or type-policy identities with PostgresRuntimeCompatibilityError. Without that option, database creation retains the lazy connection behavior and makes no artifact-compatibility claim.

Use PostgreSQL's server-enforced statement_timeout when a pool-wide statement deadline is required. createPgDatabase rejects pg's client-side query_timeout in both poolConfig and the resolved connection URI, including URIs returned by an asynchronous provider. adaptPgPool applies the same check to an application-created pool's exposed options and raw connection URI. pg can report this client timeout before the server reaches ReadyForQuery, so returning the connection to the pool would be unsafe. As a conservative fallback for opaque pool implementations, root batches and streams discard their checked-out client after a query or cursor rejection. A transaction scope cannot continue after a driver operation rejects: a root scope rolls back, while a successfully rolled-back nested savepoint lets its parent continue. The checked-out client is still discarded when the outer transaction finishes. Callback-only failures that roll back successfully do not discard an otherwise healthy client.

all, one, and maybeOne accept an AbortSignal and absolute deadline. Because node-postgres does not expose a safe signal contract for an individual pool query, typed-sql leases a client and destroys that lease when a control fires. The cancelled transaction cannot continue. This is client-side interruption by conservative connection discard, not a PostgreSQL cancel request; use server-side statement timeouts when the database itself must enforce a limit.

The runtime constructors and pg adapter accept a grammar-neutral observer. Query, prepared-query, batch, pipeline, stream, cancellation, and nested-transaction lifecycles carry PostgreSQL compiler-compatible fingerprints without exposing SQL or values. See Observe database work.

database.prepare(name, factory) returns ordinary queries carrying instance-local prepared metadata. Buffered execution passes the stable name to pg. Each connection retains at most statementCacheSize named statements (256 by default) using LRU eviction. Successful schema DDL or search_path changes advance a pool-wide generation; every connection issues DEALLOCATE ALL before its next query. The factory caches its first structural SQL skeleton and rejects duplicate names or structural drift between calls. Homogeneous fragment lists may vary only in cardinality; preparedCardinalityVariantLimit bounds their rendered per-factory LRU at 32 variants by default.

Driver failures are exposed as PostgresAdapterError with a stable kind of timeout, transaction-abort, connection-loss, server, or driver, the SQLSTATE when one exists, and the original failure as cause. These outcomes contain neither SQL text nor bound values. Explicit typed-sql cancellation remains QueryCancelledError with code TSQL_CANCELLED.

database.batch(queries) checks out one pg client and dispatches the queries sequentially. It is not a pipeline and does not combine statements into one SQL string or network round trip. Root batches use PostgreSQL's ordinary autocommit behavior; transactional statements can use an explicit typed-sql transaction when atomicity is required.

database.pipeline(queries) is the explicit lower-latency alternative for independent PostgreSQL statements. It requires pg 8.23.0 or newer. Enable node-postgres's public pipeline mode through poolConfig: { pipeline: true } or an application-created Pool({ pipeline: true }). The adapter checks the leased client's public pipeline flag, dispatches every typed query before awaiting results, and preserves exact tuple order and prepared names. It waits for all responses before releasing the client. Because later statements are already in flight, pipeline failure semantics are intentionally different from batch(): dispatch does not stop at the first server error. Root pipelines are non-atomic; transaction pipelines are atomic only through the surrounding PostgreSQL transaction.

Bulk transfer ​

The package root exports the postgresCopy capability token. Applications that use it install pg-copy-streams beside pg; ordinary execution and cursor streaming do not load that optional package. copyFrom() derives PostgreSQL COPY FROM STDIN from a typed single-row INSERT factory, while copyTo() streams raw CSV bytes from a static typed SELECT.

Both directions use client STDIN or STDOUT streams. The adapter never accepts a server filesystem path or PROGRAM, applies native backpressure, and owns connection cleanup for completion, cancellation, early export return, producer failure, and server rejection. See Transfer bulk data.

Streaming ​

Install pg-cursor only in applications that call stream():

sh
pnpm add pg-cursor

The adapter imports it when iteration starts, leases one pg pool client, and reads cursor pages according to batchSize. Completing or closing the stream closes the portal before the client is returned to the pool. Missing pg-cursor produces an actionable error at first iteration; ordinary execution and prepared factories never load it.

Cursor streaming and COPY require a pool with pipeline disabled. The pg driver rejects custom cursor and COPY queries on pipeline connections. Use a separate pipeline-enabled database for pipeline() queries when an application also streams rows.

pg-cursor always parses its cursor statement unnamed. A query produced by database.prepare() remains valid for streaming and retains its inferred row and parameter types, but the cursor path cannot reuse the prepared statement name used by buffered pg execution.

Inside a transaction, the stream reuses the transaction client and never releases it directly. The stream must complete or close before the transaction callback returns. Transaction execute(), batch(), and pipeline() calls must likewise be awaited before return; the adapter settles outstanding work before rollback and never selects commit first.

See Execute queries, Route reads and retry transactions, Database type mappings, and Compatibility.

Database JSON declarations ​

Introspection recognizes a directly enforced, validated check that calls the pg_jsonschema extension's json_matches_schema or jsonb_matches_schema routine with a literal schema and the matching JSON column. The declaration uses the supported structural JSON Schema subset. The catalog dependency must identify the extension-owned routine; a same-named application function does not establish this contract. Unvalidated checks, unenforced checks, compound predicates, and dynamic schemas retain conservative JSON types.

Named composite values converted to JSON retain their catalog field names and JSON-compatible value types. Composite fields can contain SQL null independently of constraints on a table that shares the row type. Recursive composites use the same bounded JSON shape analysis as other nested values.

JSON column parameters and explicit json/jsonb casts retain the JSON input contract independently of the result policy. They accept sql.json(value) in tagged queries and jsonValue(value) in positional query factories. SQL-standard FORMAT JSON document positions accept explicit JSON bindings too. Ordinary constructor values retain their SQL scalar behavior; cast an encoded document to json or jsonb when it must be embedded as JSON.

Native query contracts ​

createPgNativeContractAdapter from @typed-sql/postgres/pg-contracts supplies the session interface used by acquireNativeQueryContract in @typed-sql/analysis. Construct it with a dedicated application-owned pg pool and the compiler's schema input. inspectContext() captures the expected context. Acquisition describes SQL using Parse/Describe and catalog reads; it sends no Bind or Execute message for the application statement. Close the pool when generation finishes. See durable query contracts for storage and compiler-host consumption.

The adapter supports PostgreSQL 18 SELECT statements with ordinary calls, parameters, numeric/boolean literals and supported built-in casts. It also describes projections, stars, comparison/boolean filters and joins over qualified ordinary tables. String and null literals need an explicit supported built-in cast. Subqueries, compounds, table functions, sampling, custom type-input casts and unsupported expressions fail the preliminary syntax check.

Before candidate Parse, the adapter checks every referenced relation against the server catalog, locks it in access-share mode and rechecks its identity. Admitted tables are permanent heap tables with built-in scalar columns. Views, foreign tables, row-security tables, generated columns, custom/array column types, partitioning and inheritance remain unavailable through this adapter. Admission uses live metadata rather than assuming the supplied schema describes the remote objects. The native round-trip and disconnected-consumption test runs against PostgreSQL 18.3; other PostgreSQL major versions are unavailable through this acquisition adapter. This scope is separate from the full grammar's supported version range.

The session requires a primary server, UTF-8 client encoding, standard-conforming strings, pg_catalog first in effective name resolution, no temporary schema and no extensions except plpgsql. It pins relevant session settings and uses a read-only transaction with bounded statement/lock timeouts. SHA-256 catalog/context fingerprints and a WAL insertion-position guard cover metadata capture and description. Any WAL advance rejects the acquisition, including unrelated writes. Use a quiet development or migrations-derived qualification database. Context inspection retries a bounded number of unstable captures; description never relaxes its consistency guard.

RowDescription does not attest expression nullability: results remain nullable unless separate qualified evidence establishes more. Native array dimensions and opaque/custom representations remain unknown; unresolved parameter representations prevent acquisition. Exact native type modifiers are retained when reported. PostgreSQL errors and consistency failures do not publish a replacement contract.

postgresProfile() from @typed-sql/postgres/profile supplies rendering, lexical parameter occurrences, snapshot validation and policy information to createContractDialect. It has no analyze function. Its runtime metadata uses @typed-sql/postgres/tag. The explicit /analysis compatibility exports and the query entrypoint remain available. These programmatic APIs do not enable background refresh or database access during ordinary builds.

Loading the analyzer ​

Use postgresProfile() from @typed-sql/postgres/profile for lightweight contract consumption. Configure loadAnalyzer: async () => (await import("@typed-sql/postgres/analysis")).postgres() when offline inference or live reconciliation needs the full analyzer. Its versioned offline catalog is selected using snapshot server evidence. Canary versions require the explicit versionPolicy: "canary" option.

Reusable project declarations ​

createPostgresProjectCatalog from @typed-sql/postgres/project-catalog selects complete routine overload families from an introspected format-2 snapshot using the project's SQL calls. The catalog contains metadata and evidence digests, including parameter names, modes and defaults; it contains no generated executable wrappers. The constructor does not connect to a database or establish freshness: its source snapshot and context must come from the same qualified metadata capture. Serialize it as JSON and load it with parseProjectCatalog from @typed-sql/analysis.

Apply recorded catalogs with applyProjectCatalogs and createPostgresProjectCatalogContribution(). Supply the base schema, recorded context and the same type policy used for acquisition and decoding. The result contains an enriched schema and its context. Keep them together: selected catalog digests change the profile identity, and the new schema has its own hash. A changed base schema, server evidence, policy, context or installed interpreter requires matching metadata. Independent query qualification still compares claims against native query descriptions when configured.

Reusable inference currently requires an explicitly qualified routine name and a fixed scalar result with known built-in type mappings. The interpreter derives TypeScript types from the configured policy rather than copying types asserted by the metadata. Results remain nullable, including strict routines. Polymorphic, decimal-dependent, defaulted, variadic and table-result families retain their declarations but require query-specific evidence. Overloaded families need exact native argument-type matches; coercion-dependent selection requires a qualified rule or query contract. Missing or ambiguous overloads and unsupported call syntax remain conservative diagnostics. Selecting a declaration cannot silently bypass these restrictions by sharing a name with a built-in.

acquireNativeProjectCatalog from @typed-sql/analysis provides the explicit database-backed capture path. Pass a createPgNativeContractAdapter instance and the project's rendered SQL statements. With a format-2 base snapshot and matching PostgreSQL 18 server evidence, acquisition observes the context, reads matching user routine families on the same guarded lease and checks the context again before returning a catalog. It does not prepare the application statements. Missing capabilities report unavailable; changed contexts, truncated families and unsupported selections cannot publish metadata. Non-ASCII routine identifiers require explicit quoting. Normal imports and offline interpretation do not invoke this acquisition path.

Released under the MIT License.