[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-5069":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":23,"hasPages":23,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":26,"readmeContent":27,"aiSummary":28,"trendingCount":16,"starSnapshotCount":16,"syncStatus":17,"lastSyncTime":29,"discoverSource":30},5069,"pq","lib\u002Fpq","lib","Go PostgreSQL driver for database\u002Fsql","https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Flib\u002Fpq",null,"Go",9900,955,144,38,0,2,4,26,7,73.54,"MIT License",false,"master",[],"2026-06-12 04:00:24","pq is a Go PostgreSQL driver for database\u002Fsql.\n\nAll [maintained versions of PostgreSQL] are supported. Older versions may work,\nbut this is not tested. [API docs].\n\n[maintained versions of PostgreSQL]: https:\u002F\u002Fwww.postgresql.org\u002Fsupport\u002Fversioning\n[API docs]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Flib\u002Fpq\n\nConnecting\n----------\nUse the `postgres` driver name in the `sql.Open()` call:\n\n```go\npackage main\n\nimport (\n    \"database\u002Fsql\"\n    \"log\"\n\n    _ \"github.com\u002Flib\u002Fpq\" \u002F\u002F To register the driver.\n)\n\nfunc main() {\n    \u002F\u002F Or as URL: postgresql:\u002F\u002Flocalhost\u002Fpqgo\n    db, err := sql.Open(\"postgres\", \"host=localhost dbname=pqgo connect_timeout=5\")\n    if err != nil {\n        log.Fatal(err)\n    }\n    defer db.Close()\n\n    \u002F\u002F db.Open() only creates a connection pool, and doesn't actually establish\n    \u002F\u002F a connection. To ensure the connection works you need to do *something*\n    \u002F\u002F with a connection.\n    err = db.Ping()\n    if err != nil {\n        log.Fatal(err)\n    }\n}\n```\n\nYou can also use the `pq.Config` struct:\n\n```go\ncfg := pq.Config{\n\tHost:           \"localhost\",\n\tPort:           5432,\n\tUser:           \"pqgo\",\n\tConnectTimeout: 5 * time.Second,\n}\n\u002F\u002F Or: create a new Config from the defaults, environment, and DSN.\n\u002F\u002F cfg, err := pq.NewConfig(\"host=postgres dbname=pqgo\")\n\u002F\u002F if err != nil {\n\u002F\u002F     log.Fatal(err)\n\u002F\u002F }\n\nc, err := pq.NewConnectorConfig(cfg)\nif err != nil {\n    log.Fatal(err)\n}\n\n\u002F\u002F Create connection pool.\ndb := sql.OpenDB(c)\ndefer db.Close()\n\n\u002F\u002F Make sure it works.\nerr = db.Ping()\nif err != nil {\n    log.Fatal(err)\n}\n```\n\nThe DSN is identical to PostgreSQL's libpq; most parameters are supported and\nshould behave identical. Both key=value and postgres:\u002F\u002F URL-style connection\nstrings are supported. See the doc comments on the [Config struct] for the full\nlist and documentation.\n\nThe most notable difference is that you can use any [run-time parameter] such as\n`search_path` or `work_mem` in the connection string. This is different from\nlibpq, which uses the `options` parameter for this (which also works in pq).\n\nFor example:\n\n    sql.Open(\"postgres\", \"dbname=pqgo work_mem=100kB search_path=xyz\")\n\nThe libpq way (which also works in pq) is to use `options='-c k=v'` like so:\n\n    sql.Open(\"postgres\", \"dbname=pqgo options='-c work_mem=100kB -c search_path=xyz'\")\n\nIt's recommended to add `connect_timeout` to the DSN – database\u002Fsql may open new\nconnections asynchronously so it doesn't use the context from QueryContext(),\nPingContext(), etc. The default is to wait indefinitely.\n\n[Config struct]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Flib\u002Fpq#Config\n[run-time parameter]: http:\u002F\u002Fwww.postgresql.org\u002Fdocs\u002Fcurrent\u002Fstatic\u002Fruntime-config.html\n\nErrors\n------\nErrors from PostgreSQL are returned as [pq.Error]; [pq.As] can be used to\nconvert an error to `pq.Error`:\n\n```go\npqErr := pq.As(err, pqerror.UniqueViolation)\nif pqErr != nil {\n  return fmt.Errorf(\"email %q already exsts\", email)\n}\n```\n\nthe Error() string contains the error message and code:\n\n    pq: duplicate key value violates unique constraint \"users_lower_idx\" (23505)\n\nThe ErrorWithDetail() string also contains the DETAIL and CONTEXT fields, if\npresent. For example for the above error this helpfully contains the duplicate\nvalue:\n\n    ERROR:   duplicate key value violates unique constraint \"users_lower_idx\" (23505)\n    DETAIL:  Key (lower(email))=(a@example.com) already exists.\n\nOr for an invalid syntax error like this:\n\n    pq: invalid input syntax for type json (22P02)\n\nIt contains the context where this error occurred:\n\n    ERROR:   invalid input syntax for type json (22P02)\n    DETAIL:  Token \"asd\" is invalid.\n    CONTEXT: line 5, column 8:\n\n          3 | 'def',\n          4 | 123,\n          5 | 'foo', 'asd'::jsonb\n                     ^\n\n[pq.Error]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Flib\u002Fpq#Error\n[pq.As]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Flib\u002Fpq#As\n\nPostgreSQL features\n-------------------\n\n### Authentication\npq supports PASSWORD, MD5, and SCRAM-SHA256 authentication out of the box. If\nyou need GSS\u002FKerberos authentication you'll need to import the `auth\u002Fkerberos`\nmodule: package:\n\n\timport \"github.com\u002Flib\u002Fpq\u002Fauth\u002Fkerberos\"\n\n\tfunc init() {\n\t\tpq.RegisterGSSProvider(func() (pq.Gss, error) { return kerberos.NewGSS() })\n\t}\n\nThis is in a separate module so that users who don't need Kerberos (i.e. most\nusers) don't have to add unnecessary dependencies.\n\nReading a [password file] (pgpass) is also supported.\n\n[password file]: http:\u002F\u002Fwww.postgresql.org\u002Fdocs\u002Fcurrent\u002Fstatic\u002Flibpq-pgpass.html\n\n### Bulk imports with `COPY [..] FROM STDIN`\nYou can perform bulk imports by preparing a `COPY [..] FROM STDIN` statement\ninside a transaction. The returned `sql.Stmt` can then be repeatedly executed to\ncopy data. After all data has been processed you should call Exec() once with no\narguments to flush all buffered data.\n\n[Further documentation][copy-doc] and [example][copy-ex].\n\n[copy-doc]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Flib\u002Fpq#hdr-Bulk_imports\n[copy-ex]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Flib\u002Fpq#example-package-CopyFromStdin\n\n### NOTICE errors\nPostgreSQL has \"NOTICE\" errors for informational messages. For example from the\npsql CLI:\n\n    pqgo=# drop table if exists doesnotexist;\n    NOTICE:  table \"doesnotexist\" does not exist, skipping\n    DROP TABLE\n\nThese errors are not returned because they're not really errors but, well,\nnotices.\n\nYou can register a callback for these notices with [ConnectorWithNoticeHandler]\n\n[ConnectorWithNoticeHandler]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Flib\u002Fpq#ConnectorWithNoticeHandler\n\n### Using `LISTEN`\u002F`NOTIFY`\nWith [pq.Listener] notifications are send on a channel. For example:\n\n```go\nl := pq.NewListener(\"dbname=pqgo\", time.Second, time.Minute, nil)\ndefer l.Close()\n\nerr := l.Listen(\"coconut\")\nif err != nil {\n    log.Fatal(err)\n}\n\nfor {\n    n := \u003C-l.Notify:\n    if n == nil {\n        fmt.Println(\"nil notify: closing Listener\")\n        return\n    }\n    fmt.Printf(\"notification on %q with data %q\\n\", n.Channel, n.Extra)\n}\n```\n\nAnd you'll get a notification for every `notify coconut`.\n\nSee the API docs for a more complete example.\n\n[pq.Listener]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Flib\u002Fpq#Listener\n\n\nCaveats\n-------\n### LastInsertId\nsql.Result.LastInsertId() is not supported, because the PostgreSQL protocol does\nnot have this facility. Use  `insert [..] returning [cols]` instead:\n\n    db.QueryRow(`insert into tbl [..] returning id_col`).Scan(..)\n    \u002F\u002F Or multiple rows:\n    db.Query(`insert into tbl (row1), (row2) returning id_col`)\n\nThis will also work in SQLite and MariaDB with the same syntax. MS-SQL and\nOracle have a similar facility (with a different syntax).\n\n### timestamps\nFor timestamps with a timezone (`timestamptz`\u002F`timestamp with time zone`), pq\nuses the timezone configured in the server, as libpq. You can change this with\n`timestamp=[..]` in the connection string. It's generally recommended to use\nUTC.\n\nFor timestamps without a timezone (`timestamp`\u002F`timestamp without time zone`),\npq always uses `time.FixedZone(\"\", 0)` as the timezone; the timestamp parameter\nhas no effect here. This is intentionally not equal to time.UTC, as it's not a\nUTC time: it's a time without a timezone. Go's time package does not really\nsupport this concept, so this is the best we can do This will print `+0000`\ntwice (e.g. `2026-03-15 17:45:47 +0000 +0000`; having a clearer name would have\nbeen better, but is not compatible change). See [this comment][ts] for some\noptions on how to deal with this.\n\nAlso see the examples for [timestamptz] and [timestamp]\n\n[ts]: https:\u002F\u002Fgithub.com\u002Flib\u002Fpq\u002Fissues\u002F329#issuecomment-4025733506\n[timestamptz]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Flib\u002Fpq#example-package-TimestampWithTimezone\n[timestamp]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Flib\u002Fpq#example-package-TimestampWithoutTimezone\n\n### bytea with copy\nAll `[]byte` parameters are encoded as `bytea` when using `copy [..] from\nstdin`, which may result in errors for e.g. `jsonb` columns. The solution is to\nuse a string instead of []byte. See #1023\n\nDevelopment\n-----------\n### Running tests\nTests need to be run against a PostgreSQL database; you can use Docker compose\nto start one:\n\n    docker compose up -d\n\nThis starts the latest PostgreSQL; use `docker compose up -d pg«v»` to start a\ndifferent version.\n\nIn addition, your `\u002Fetc\u002Fhosts` needs an entry:\n\n    127.0.0.1 postgres postgres-invalid\n\nOr you can use any other PostgreSQL instance; see\n`testdata\u002Fpostgres\u002Fdocker-entrypoint-initdb.d` for the required setup. You can use\nthe standard `PG*` environment variables to control the connection details; it\nuses the following defaults:\n\n    PGHOST=localhost\n    PGDATABASE=pqgo\n    PGUSER=pqgo\n    PGSSLMODE=disable\n    PGCONNECT_TIMEOUT=20\n\n`PQTEST_BINARY_PARAMETERS` can be used to add `binary_parameters=yes` to all\nconnection strings:\n\n    PQTEST_BINARY_PARAMETERS=1 go test\n\nTests can be run against pgbouncer with:\n\n    docker compose up -d pgbouncer pg18\n    PGPORT=6432 go test .\u002F...\n\nand pgpool with:\n\n    docker compose up -d pgpool pg18\n    PGPORT=7432 go test .\u002F...\n\n### Protocol debug output\nYou can use PQGO_DEBUG=1 to make the driver print the communication with\nPostgreSQL to stderr; this works anywhere (test or applications) and can be\nuseful to debug protocol problems.\n\nFor example:\n\n    % PQGO_DEBUG=1 go test -run TestSimpleQuery\n    CLIENT → Startup                 69  \"\\x00\\x03\\x00\\x00database\\x00pqgo\\x00user [..]\"\n    SERVER ← (R) AuthRequest          4  \"\\x00\\x00\\x00\\x00\"\n    SERVER ← (S) ParamStatus         19  \"in_hot_standby\\x00off\\x00\"\n    [..]\n    SERVER ← (Z) ReadyForQuery        1  \"I\"\n             START conn.query\n             START conn.simpleQuery\n    CLIENT → (Q) Query                9  \"select 1\\x00\"\n    SERVER ← (T) RowDescription      29  \"\\x00\\x01?column?\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x17\\x00\\x04\\xff\\xff\\xff\\xff\\x00\\x00\"\n    SERVER ← (D) DataRow              7  \"\\x00\\x01\\x00\\x00\\x00\\x011\"\n             END conn.simpleQuery\n             END conn.query\n    SERVER ← (C) CommandComplete      9  \"SELECT 1\\x00\"\n    SERVER ← (Z) ReadyForQuery        1  \"I\"\n    CLIENT → (X) Terminate            0  \"\"\n    PASS\n    ok      github.com\u002Flib\u002Fpq       0.010s\n","lib\u002Fpq 是一个为 Go 语言设计的 PostgreSQL 数据库驱动，用于与 database\u002Fsql 包配合使用。它支持所有维护中的 PostgreSQL 版本，并提供了丰富的配置选项来连接数据库，包括通过 DSN 或 URL 格式的连接字符串以及使用 pq.Config 结构体进行更细粒度的设置。此外，该驱动还允许在连接字符串中直接指定运行时参数，这使得数据库连接更加灵活可控。适用于需要高效、稳定地与 PostgreSQL 数据库交互的 Go 应用场景，特别是在对性能和资源管理有较高要求的企业级应用开发中。","2026-06-11 03:02:21","top_language"]