finds.dev← search

// the find

lib/pq

★ 9,901 · Go · MIT · updated May 2026

Go PostgreSQL driver for database/sql

lib/pq is the original pure-Go PostgreSQL driver for database/sql. It has been the de facto standard for Go+Postgres for over a decade and covers the full PostgreSQL wire protocol without cgo. If you're picking up a Go codebase that talks to Postgres, there's a good chance it's already using this.

The PQGO_DEBUG protocol tracer is genuinely useful — seeing raw wire traffic formatted as CLIENT→/SERVER← beats staring at Wireshark. The error handling story is better than most drivers: pq.Error exposes the PostgreSQL error code, detail, and context fields directly, and pq.As lets you match on specific error codes like UniqueViolation without string parsing. COPY FROM STDIN bulk import support is well-tested and the test suite runs against pgbouncer and pgpool too, not just vanilla Postgres. The timestamp handling caveat for timestamptz vs timestamp is documented honestly rather than papered over.

pgx has been the better choice for new projects for several years now — it supports pipeline mode, logical replication, and pgvector natively, while lib/pq is stuck in the database/sql abstraction which hides protocol-level features. The bytea-in-COPY bug (issue #1023, []byte columns treated as bytea even for jsonb) is a silent data corruption risk with no fix, just a workaround. The Listener API for LISTEN/NOTIFY uses a raw channel with nil as a sentinel for reconnects, which is easy to mishandle in production. LastInsertId() silently returns zero rather than an error, so code ported from MySQL will appear to work and return wrong data.

View on GitHub → Homepage ↗

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →