{"id":13412272,"url":"https://github.com/jackc/pgx","last_synced_at":"2025-09-09T21:16:11.596Z","repository":{"id":7752997,"uuid":"9120526","full_name":"jackc/pgx","owner":"jackc","description":"PostgreSQL driver and toolkit for Go","archived":false,"fork":false,"pushed_at":"2025-05-03T18:46:46.000Z","size":5519,"stargazers_count":11741,"open_issues_count":220,"forks_count":905,"subscribers_count":104,"default_branch":"master","last_synced_at":"2025-05-05T15:19:22.625Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/jackc/pgx/v5","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jackc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-03-30T19:06:26.000Z","updated_at":"2025-05-05T09:30:16.000Z","dependencies_parsed_at":"2024-01-13T04:56:14.197Z","dependency_job_id":"a92c4626-e572-4a14-89d2-9506f56d3327","html_url":"https://github.com/jackc/pgx","commit_stats":{"total_commits":3453,"total_committers":338,"mean_commits":"10.215976331360947","dds":0.2479003764842166,"last_synced_commit":"c76a650f75781d7114612d848922868ab190e868"},"previous_names":[],"tags_count":101,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackc%2Fpgx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackc%2Fpgx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackc%2Fpgx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackc%2Fpgx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jackc","download_url":"https://codeload.github.com/jackc/pgx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252522175,"owners_count":21761685,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:01:22.853Z","updated_at":"2025-09-09T21:16:11.567Z","avatar_url":"https://github.com/jackc.png","language":"Go","readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/jackc/pgx/v5.svg)](https://pkg.go.dev/github.com/jackc/pgx/v5)\n[![Build Status](https://github.com/jackc/pgx/actions/workflows/ci.yml/badge.svg)](https://github.com/jackc/pgx/actions/workflows/ci.yml)\n\n# pgx - PostgreSQL Driver and Toolkit\n\npgx is a pure Go driver and toolkit for PostgreSQL.\n\nThe pgx driver is a low-level, high performance interface that exposes PostgreSQL-specific features such as `LISTEN` /\n`NOTIFY` and `COPY`. It also includes an adapter for the standard `database/sql` interface.\n\nThe toolkit component is a related set of packages that implement PostgreSQL functionality such as parsing the wire protocol\nand type mapping between PostgreSQL and Go. These underlying packages can be used to implement alternative drivers,\nproxies, load balancers, logical replication clients, etc.\n\n## Example Usage\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/jackc/pgx/v5\"\n)\n\nfunc main() {\n\t// urlExample := \"postgres://username:password@localhost:5432/database_name\"\n\tconn, err := pgx.Connect(context.Background(), os.Getenv(\"DATABASE_URL\"))\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"Unable to connect to database: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\tdefer conn.Close(context.Background())\n\n\tvar name string\n\tvar weight int64\n\terr = conn.QueryRow(context.Background(), \"select name, weight from widgets where id=$1\", 42).Scan(\u0026name, \u0026weight)\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"QueryRow failed: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\n\tfmt.Println(name, weight)\n}\n```\n\nSee the [getting started guide](https://github.com/jackc/pgx/wiki/Getting-started-with-pgx) for more information.\n\n## Features\n\n* Support for approximately 70 different PostgreSQL types\n* Automatic statement preparation and caching\n* Batch queries\n* Single-round trip query mode\n* Full TLS connection control\n* Binary format support for custom types (allows for much quicker encoding/decoding)\n* `COPY` protocol support for faster bulk data loads\n* Tracing and logging support\n* Connection pool with after-connect hook for arbitrary connection setup\n* `LISTEN` / `NOTIFY`\n* Conversion of PostgreSQL arrays to Go slice mappings for integers, floats, and strings\n* `hstore` support\n* `json` and `jsonb` support\n* Maps `inet` and `cidr` PostgreSQL types to `netip.Addr` and `netip.Prefix`\n* Large object support\n* NULL mapping to pointer to pointer\n* Supports `database/sql.Scanner` and `database/sql/driver.Valuer` interfaces for custom types\n* Notice response handling\n* Simulated nested transactions with savepoints\n\n## Choosing Between the pgx and database/sql Interfaces\n\nThe pgx interface is faster. Many PostgreSQL specific features such as `LISTEN` / `NOTIFY` and `COPY` are not available\nthrough the `database/sql` interface.\n\nThe pgx interface is recommended when:\n\n1. The application only targets PostgreSQL.\n2. No other libraries that require `database/sql` are in use.\n\nIt is also possible to use the `database/sql` interface and convert a connection to the lower-level pgx interface as needed.\n\n## Testing\n\nSee [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions.\n\n## Architecture\n\nSee the presentation at Golang Estonia, [PGX Top to Bottom](https://www.youtube.com/watch?v=sXMSWhcHCf8) for a description of pgx architecture.\n\n## Supported Go and PostgreSQL Versions\n\npgx supports the same versions of Go and PostgreSQL that are supported by their respective teams. For [Go](https://golang.org/doc/devel/release.html#policy) that is the two most recent major releases and for [PostgreSQL](https://www.postgresql.org/support/versioning/) the major releases in the last 5 years. This means pgx supports Go 1.24 and higher and PostgreSQL 13 and higher. pgx also is tested against the latest version of [CockroachDB](https://www.cockroachlabs.com/product/).\n\n## Version Policy\n\npgx follows semantic versioning for the documented public API on stable releases. `v5` is the latest stable major version.\n\n## PGX Family Libraries\n\n### [github.com/jackc/pglogrepl](https://github.com/jackc/pglogrepl)\n\npglogrepl provides functionality to act as a client for PostgreSQL logical replication.\n\n### [github.com/jackc/pgmock](https://github.com/jackc/pgmock)\n\npgmock offers the ability to create a server that mocks the PostgreSQL wire protocol. This is used internally to test pgx by purposely inducing unusual errors. pgproto3 and pgmock together provide most of the foundational tooling required to implement a PostgreSQL proxy or MitM (such as for a custom connection pooler).\n\n### [github.com/jackc/tern](https://github.com/jackc/tern)\n\ntern is a stand-alone SQL migration system.\n\n### [github.com/jackc/pgerrcode](https://github.com/jackc/pgerrcode)\n\npgerrcode contains constants for the PostgreSQL error codes.\n\n## Adapters for 3rd Party Types\n\n* [github.com/jackc/pgx-gofrs-uuid](https://github.com/jackc/pgx-gofrs-uuid)\n* [github.com/jackc/pgx-shopspring-decimal](https://github.com/jackc/pgx-shopspring-decimal)\n* [github.com/twpayne/pgx-geos](https://github.com/twpayne/pgx-geos) ([PostGIS](https://postgis.net/) and [GEOS](https://libgeos.org/) via [go-geos](https://github.com/twpayne/go-geos))\n* [github.com/vgarvardt/pgx-google-uuid](https://github.com/vgarvardt/pgx-google-uuid)\n\n\n## Adapters for 3rd Party Tracers\n\n* [github.com/jackhopner/pgx-xray-tracer](https://github.com/jackhopner/pgx-xray-tracer)\n* [github.com/exaring/otelpgx](https://github.com/exaring/otelpgx)\n\n## Adapters for 3rd Party Loggers\n\nThese adapters can be used with the tracelog package.\n\n* [github.com/jackc/pgx-go-kit-log](https://github.com/jackc/pgx-go-kit-log)\n* [github.com/jackc/pgx-log15](https://github.com/jackc/pgx-log15)\n* [github.com/jackc/pgx-logrus](https://github.com/jackc/pgx-logrus)\n* [github.com/jackc/pgx-zap](https://github.com/jackc/pgx-zap)\n* [github.com/jackc/pgx-zerolog](https://github.com/jackc/pgx-zerolog)\n* [github.com/mcosta74/pgx-slog](https://github.com/mcosta74/pgx-slog)\n* [github.com/kataras/pgx-golog](https://github.com/kataras/pgx-golog)\n\n## 3rd Party Libraries with PGX Support\n\n### [github.com/pashagolub/pgxmock](https://github.com/pashagolub/pgxmock)\n\npgxmock is a mock library implementing pgx interfaces.\npgxmock has one and only purpose - to simulate pgx behavior in tests, without needing a real database connection.\n\n### [github.com/georgysavva/scany](https://github.com/georgysavva/scany)\n\nLibrary for scanning data from a database into Go structs and more.\n\n### [github.com/vingarcia/ksql](https://github.com/vingarcia/ksql)\n\nA carefully designed SQL client for making using SQL easier,\nmore productive, and less error-prone on Golang.\n\n### [github.com/otan/gopgkrb5](https://github.com/otan/gopgkrb5)\n\nAdds GSSAPI / Kerberos authentication support.\n\n### [github.com/wcamarao/pmx](https://github.com/wcamarao/pmx)\n\nExplicit data mapping and scanning library for Go structs and slices.\n\n### [github.com/stephenafamo/scan](https://github.com/stephenafamo/scan)\n\nType safe and flexible package for scanning database data into Go types.\nSupports, structs, maps, slices and custom mapping functions.\n\n### [github.com/z0ne-dev/mgx](https://github.com/z0ne-dev/mgx)\n\nCode first migration library for native pgx (no database/sql abstraction).\n\n### [github.com/amirsalarsafaei/sqlc-pgx-monitoring](https://github.com/amirsalarsafaei/sqlc-pgx-monitoring)\n\nA database monitoring/metrics library for pgx and sqlc. Trace, log and monitor your sqlc query performance using OpenTelemetry.\n\n### [https://github.com/nikolayk812/pgx-outbox](https://github.com/nikolayk812/pgx-outbox)\n\nSimple Golang implementation for transactional outbox pattern for PostgreSQL using jackc/pgx driver.\n\n### [https://github.com/Arlandaren/pgxWrappy](https://github.com/Arlandaren/pgxWrappy)\n\nSimplifies working with the pgx library, providing convenient scanning of nested structures.\n\n## [https://github.com/KoNekoD/pgx-colon-query-rewriter](https://github.com/KoNekoD/pgx-colon-query-rewriter)\n\nImplementation of the pgx query rewriter to use ':' instead of '@' in named query parameters.\n","funding_links":[],"categories":["Database Clients \u0026 Tools","Go","Database","Database Drivers","Data Integration Frameworks","Libraries and Clients","Relational Databases","Generators","数据库驱动","\u003cspan id=\"数据库驱动-database-drivers\"\u003e数据库驱动 Database Drivers\u003c/span\u003e","数据库驱动`连接和操作数据库工具`","数据库驱动程序","Compiled list","數據庫驅動"],"sub_categories":["Relational Database Drivers","Advanced Console UIs","SQL 查询语句构建库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","关系数据库驱动程序","plv8:","高級控制台界面","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackc%2Fpgx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjackc%2Fpgx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackc%2Fpgx/lists"}