About this project

lib/pq is a pure Go implementation of a PostgreSQL driver that integrates with Go's standard database/sql package. It supports all currently maintained versions of PostgreSQL and provides a familiar DSN format compatible with libpq, accepting both key=value and postgres:// URL-style connection strings. Key features include: - **Authentication**: Supports PASSWORD, MD5, and SCRAM-SHA256 out of the box. Optional GSS/Kerberos authentication is available via a separate auth/kerberos module to avoid unnecessary dependencies. pgpass file support is also included. - **Bulk imports**: COPY [..] FROM STDIN is supported for efficient bulk data loading within transactions. - **LISTEN/NOTIFY**: A pq.Listener type delivers PostgreSQL notifications on a Go channel, enabling real-time event-driven patterns. - **Error handling**: PostgreSQL errors are returned as pq.Error with structured fields. The pq.As helper converts errors to typed pq.Error values, and ErrorWithDetail() includes DETAIL and CONTEXT information for debugging. - **NOTICE handling**: Informational NOTICE messages from PostgreSQL can be captured via a configurable callback handler. - **Runtime parameters**: Unlike libpq, pq allows setting runtime parameters like search_path or work_mem directly in the connection string. - **Config struct**: A pq.Config struct provides programmatic connection configuration, with pq.NewConfig parsing DSN strings and pq.NewConnectorConfig creating a connector. Caveats documented in the README include: LastInsertId is not supported (use INSERT ... RETURNING instead), timestamp handling uses server timezone for timestamptz and a fixed zero-offset zone for timestamp without timezone, and bytea encoding during COPY may cause issues with jsonb columns. The project includes a comprehensive test suite runnable via Docker Compose against multiple PostgreSQL versions, pgbouncer, and pgpool. A PQGO_DEBUG=1 environment variable enables protocol-level debug output for troubleshooting.