{"id":40906165,"url":"https://github.com/tomyl/pg-dump-upsert","last_synced_at":"2026-01-22T02:38:37.554Z","repository":{"id":48461885,"uuid":"140997128","full_name":"tomyl/pg-dump-upsert","owner":"tomyl","description":"Simple tool to dump a Postgresql table as INSERT statements with ON CONFLICT clause","archived":false,"fork":false,"pushed_at":"2025-04-19T20:31:06.000Z","size":103,"stargazers_count":16,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-19T22:05:38.536Z","etag":null,"topics":["go","pg-dump","postgresql"],"latest_commit_sha":null,"homepage":null,"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/tomyl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2018-07-15T04:06:58.000Z","updated_at":"2025-04-19T20:31:03.000Z","dependencies_parsed_at":"2022-09-11T23:21:11.877Z","dependency_job_id":"f02b51ff-b790-405e-b3bb-bb0845bcc94d","html_url":"https://github.com/tomyl/pg-dump-upsert","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tomyl/pg-dump-upsert","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomyl%2Fpg-dump-upsert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomyl%2Fpg-dump-upsert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomyl%2Fpg-dump-upsert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomyl%2Fpg-dump-upsert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomyl","download_url":"https://codeload.github.com/tomyl/pg-dump-upsert/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomyl%2Fpg-dump-upsert/sbom","scorecard":{"id":893412,"data":{"date":"2025-08-11","repo":{"name":"github.com/tomyl/pg-dump-upsert","commit":"75b0451b9645afe61d6a7c0c53e78a45de8104d3"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.5,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":1,"reason":"Found 2/15 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/tomyl/pg-dump-upsert/ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/tomyl/pg-dump-upsert/ci.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 17 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-24T12:45:33.973Z","repository_id":48461885,"created_at":"2025-08-24T12:45:33.973Z","updated_at":"2025-08-24T12:45:33.973Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28651809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T01:17:37.254Z","status":"online","status_checked_at":"2026-01-22T02:00:07.137Z","response_time":144,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["go","pg-dump","postgresql"],"created_at":"2026-01-22T02:38:37.501Z","updated_at":"2026-01-22T02:38:37.548Z","avatar_url":"https://github.com/tomyl.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pg-dump-upsert :elephant::poop:\n\n![CI](https://github.com/tomyl/pg-dump-upsert/actions/workflows/ci.yml/badge.svg?branch=master\u0026event=push)\n[![GoDoc](https://godoc.org/github.com/tomyl/pg-dump-upsert/pgdump?status.png)](http://godoc.org/github.com/tomyl/pg-dump-upsert/pgdump)\n[![Go Report Card](https://goreportcard.com/badge/github.com/tomyl/pg-dump-upsert)](https://goreportcard.com/report/github.com/tomyl/pg-dump-upsert)\n\nSimple tool to dump a Postgresql table as `INSERT` statements with `ON\nCONFLICT` clause (also known as \"upsert\" statements).\n\n**Pre-alpha software**. Expect crashes, data loss, silent data corruption etc.\n\n# Rationale\n\nThe [pg\\_dump](https://www.postgresql.org/docs/current/static/app-pgdump.html)\ncommand can dump tables as `INSERT` statements however you can't directly\nrestore such dumps if the database has conflicting rows. Furthermore `pg_dump`\nis doing more work than simply querying the data and this sometimes causes\nseemingly unrelated failures.\n\n# Installation\n\n```bash\n$ go install github.com/tomyl/pg-dump-upsert@latest\n$ pg-dump-upsert -h\nUsage of pg-dump-upsert:\n  -conflict-column string\n        Append an ON CONFLICT clause for this column. All other columns will be included in a DO UPDATE SET list.\n  -dsn string\n        Connection string. Example: postgres://user:password@host:5432/db\n  -from string\n        Source table to dump.\n  -insert-columns string\n        Comma-separated list of columns to include in INSERT statement. Defaults to all columns.\n  -noconflict\n        Append ON CONFLICT DO NOTHING.\n  -query string\n        Use custom SELECT query. By default fetches all rows. Note that column order must match -insert-columns. It is also valid to just specify a WHERE clause. It will be appended to the default query.\n  -to string\n        Table name to use in INSERT statements. Defaults to the source table.\n  -tx   \n        Wrap INSERT statements in transaction.\n  -verbose\n        Log query statement to stderr.\n```\n\n# Examples\n\nDump all rows in table `employee`:\n\n```bash\n$ pg-dump-upsert -dsn \"postgres://user:password@host:5432/db\" -from employee \nINSERT INTO employee (id, created_at, name, salary) VALUES (1, '2018-06-13 21:10:34.769555+08', 'Jane Doe', 123456);\n...\n```\n\nChoose which columns to dump:\n\n```bash\n$ pg-dump-upsert -dsn \"postgres://user:password@host:5432/db\" -from employee -insert-columns id,name\nINSERT INTO employee (id, name) VALUES (1, 'Jane Doe');\n...\n```\n\nIgnore conflicts:\n\n```bash\n$ pg-dump-upsert -dsn \"postgres://user:password@host:5432/db\" -from employee -noconflict\nINSERT INTO employee (id, created_at, name, salary) VALUES (1, '2018-06-13 21:10:34.769555+08', 'Jane Doe' 123456) ON CONFLICT DO NOTHING;\n...\n```\n\nUpdate columns on conflict:\n\n```bash\n$ pg-dump-upsert -dsn \"postgres://user:password@host:5432/db\" -from employee -conflict-column id\nINSERT INTO employee (id, created_at, name, salary) VALUES (1, '2018-06-13 21:10:34.769555+08', 'Jane Doe', 123456) ON CONFLICT (id) DO UPDATE SET created_at=EXCLUDED.created_at, name=EXCLUDED.name;\n...\n```\n\nFetch a subset of the rows:\n\n```bash\n$ pg-dump-upsert -dsn \"postgres://user:password@host:5432/db\" -from employee -query \"WHERE salary \u003e 12345\"\nINSERT INTO employee (id, created_at, name, salary) VALUES (1, '2018-06-13 21:10:34.769555+08', 'Jane Doe', 123456);\n...\n```\n\nUse a different table name in the `INSERT` statements:\n\n```bash\n$ pg-dump-upsert -dsn \"postgres://user:password@host:5432/db\" -from employee -to minions\nINSERT INTO minions (id, created_at, name, salary) VALUES (1, '2018-06-13 21:10:34.769555+08', 'Jane Doe', 123456);\n...\n```\n\nTo restore a dump, simply use the `\\i` command in `psql`.\n\n# TODO\n- [ ] Implement support for all Postgres data types.\n- [ ] Skip generated columns when dumping views.\n- [ ] Allow which columns to update when specifying `-conflict-column`?\n- [ ] More unit tests would be nice...\n- [ ] Finish this TODO list.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomyl%2Fpg-dump-upsert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomyl%2Fpg-dump-upsert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomyl%2Fpg-dump-upsert/lists"}