A pure Go PostgreSQL driver for the database/sql package, supporting all maintained PostgreSQL versions.
lib/pq is a PostgreSQL database driver for Go's standard `database/sql` package. It provides a robust and feature-complete interface for Go applications to interact with PostgreSQL databases by implementing the PostgreSQL wire protocol directly in Go.
Go developers building applications that require reliable and full-featured PostgreSQL database connectivity, particularly those needing advanced PostgreSQL-specific features like LISTEN/NOTIFY or bulk imports.
Developers choose lib/pq for its strict compatibility with PostgreSQL's native behavior and libpq connection string format, its implementation of PostgreSQL-specific features like structured error handling and COPY FROM STDIN for bulk imports, and its philosophy prioritizing correctness and standards compliance over convenience.
Go PostgreSQL driver for database/sql
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports all maintained PostgreSQL versions and uses an identical DSN format to libpq, ensuring seamless integration and minimal migration effort for existing PostgreSQL users.
Provides pq.Error and pq.As for detailed error information, including PostgreSQL error codes, DETAIL, and CONTEXT fields, which aids in precise debugging and error recovery.
Implements COPY FROM STDIN for bulk data loading, leveraging PostgreSQL's native bulk import capability for high-performance data insertion directly from Go applications.
Includes pq.Listener for LISTEN/NOTIFY functionality via channels and allows setting runtime parameters like search_path directly in connection strings, covering many PostgreSQL-specific use cases.
The driver does not support sql.Result.LastInsertId() due to PostgreSQL protocol limitations, forcing developers to rewrite queries with RETURNING clauses, which can be a breaking change for some codebases.
Handling of timestamp data types has quirks, such as using time.FixedZone("", 0) for timestamps without timezone, leading to potential confusion and requiring manual timezone management in applications.
When using COPY FROM STDIN, all []byte parameters are encoded as bytea, causing errors for jsonb columns and necessitating workarounds like using strings, as acknowledged in the README issue #1023.