API Reference

postgres.js

A fast, thin PostgreSQL client for Node.js using tagged template queries and simple connection pooling.

Official Documentation ↗
CompatibilityThis documentation covers version v4.0.0. Check the official docs for the latest API surface.

Installation

npmnpm install postgres

Methods

postgres.js uses tagged template literals to build parameterized queries and pools connections automatically.

Key Features

  • Tagged template queries with automatic parameterization
  • Automatic connection pooling
  • Listen/notify and COPY support

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/porsager/postgres@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:51:47.353Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/porsager/postgres@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:51:47.353Z.

FAQ

Is the tagged template safe from SQL injection?
Yes. Interpolated values become bound parameters, so sql`... ${value}` is safe, but you must never build the query string manually.
Does it support connection pooling?
Yes. A single sql instance pools connections and reuses them; do not create one instance per request.
How do I use transactions?
Call sql.begin(async (sql) => { ... }) to run a callback inside a transaction, rolling back if it throws.