{"id":13513415,"url":"https://github.com/fboulnois/pg_uuidv7","last_synced_at":"2025-04-12T18:48:33.219Z","repository":{"id":140693387,"uuid":"584503581","full_name":"fboulnois/pg_uuidv7","owner":"fboulnois","description":"A tiny Postgres extension to create version 7 UUIDs","archived":false,"fork":false,"pushed_at":"2024-10-08T23:59:00.000Z","size":32,"stargazers_count":301,"open_issues_count":8,"forks_count":26,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-10-11T18:11:41.574Z","etag":null,"topics":["c","libpq","postgres","postgresql","postgresql-extension","uuid","uuid-generator","uuidv7"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fboulnois.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}},"created_at":"2023-01-02T18:52:11.000Z","updated_at":"2024-10-11T08:10:50.000Z","dependencies_parsed_at":"2023-11-29T01:29:52.815Z","dependency_job_id":"b8bbd3b2-b08d-43ac-be8d-a678a80168a8","html_url":"https://github.com/fboulnois/pg_uuidv7","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fboulnois%2Fpg_uuidv7","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fboulnois%2Fpg_uuidv7/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fboulnois%2Fpg_uuidv7/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fboulnois%2Fpg_uuidv7/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fboulnois","download_url":"https://codeload.github.com/fboulnois/pg_uuidv7/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618035,"owners_count":21134197,"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":["c","libpq","postgres","postgresql","postgresql-extension","uuid","uuid-generator","uuidv7"],"created_at":"2024-08-01T05:00:24.540Z","updated_at":"2025-04-12T18:48:33.195Z","avatar_url":"https://github.com/fboulnois.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# `pg_uuidv7`: Use the new v7 UUIDs in Postgres\n\nA tiny Postgres extension to create valid [version 7 UUIDs](https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-00.html#name-uuid-version-7)\nin Postgres.\n\nThese are regular Postgres UUIDs, so they can be used as primary keys, converted\nto and from strings, included in indexes, etc:\n\n```sql\nSELECT uuid_generate_v7();\n\n           uuid_generate_v7           \n--------------------------------------\n 018570bb-4a7d-7c7e-8df4-6d47afd8c8fc\n(1 row)\n```\n\nThe timestamp component of these UUIDs can be extracted:\n\n```sql\nSELECT uuid_v7_to_timestamptz('018570bb-4a7d-7c7e-8df4-6d47afd8c8fc');\n   uuid_v7_to_timestamptz\n----------------------------\n 2023-01-02 04:26:40.637+00\n(1 row)\n```\n\nTimestamps can be converted to v7 UUIDs:\n\n```sql\nSELECT uuid_timestamptz_to_v7('2023-01-02 04:26:40.637+00');\n        uuid_timestamptz_to_v7\n--------------------------------------\n 018570bb-4a7d-7630-a5c4-89b795024c5d\n(1 row)\n\n-- for date range queries set the second argument to true to zero the random bits\nSELECT uuid_timestamptz_to_v7('2023-01-02 04:26:40.637+00', true);\n        uuid_timestamptz_to_v7\n--------------------------------------\n 018570bb-4a7d-7000-8000-000000000000\n(1 row)\n```\n\n`uuid_generate_v7()` is as fast as the native `gen_random_uuid()` function. See\nthe [benchmarks](BENCHMARKS.md) for more details.\n\n## Background\n\nVersion 7 UUIDs have a few advantages. They include a 48-bit Unix timestamp with\nmillisecond accuracy and will overflow far in the future (10899 AD). They also\ninclude 74 random bits which means [billions can be created every second](https://en.wikipedia.org/wiki/Birthday_problem#Probability_table)\nwithout collisions. Because of their structure they are globally sortable and\ncan be created in parallel in a distributed system.\n\n## Quickstart\n\n\u003e [!IMPORTANT]\n\u003e These instructions are for x86_64 Linux. On other architectures (e.g. Apple\nM1, Raspberry Pi, etc.) follow the [build instructions](#build) instead.\n\n1. Download the [latest `.tar.gz` release](https://github.com/fboulnois/pg_uuidv7/releases)\nand extract it to a temporary directory\n2. Copy `pg_uuidv7.so` for your Postgres version into the Postgres module\ndirectory\n3. Copy `pg_uuidv7--1.6.sql` and `pg_uuidv7.control` into the Postgres extension\ndirectory\n4. Enable the extension in the database using `CREATE EXTENSION pg_uuidv7;`\n\n```sh\n# example shell script to install pg_uuidv7\ncd \"$(mktemp -d)\"\ncurl -LO \"https://github.com/fboulnois/pg_uuidv7/releases/download/v1.6.0/{pg_uuidv7.tar.gz,SHA256SUMS}\"\ntar xf pg_uuidv7.tar.gz\nsha256sum -c SHA256SUMS\nPG_MAJOR=$(pg_config --version | sed 's/^.* \\([0-9]\\{1,\\}\\).*$/\\1/')\ncp \"$PG_MAJOR/pg_uuidv7.so\" \"$(pg_config --pkglibdir)\"\ncp pg_uuidv7--1.6.sql pg_uuidv7.control \"$(pg_config --sharedir)/extension\"\npsql -c \"CREATE EXTENSION pg_uuidv7;\"\n```\n\n## Build\n\n### Build locally\n\n`pg_uuidv7` only requires the `libpq` headers and Postgres extension tools to\nbuild the code. On Debian, these headers are included in the `libpq-dev` and\n`postgresql-server-dev-all` packages.\n\nTo build the code run `make`. To install the extension locally run `make install`.\n\n### Build using Docker\n\nA [`Dockerfile`](Dockerfile) is available to build the code using the official\nPostgres Docker image:\n\n```sh\ndocker build . --tag pg_uuidv7\n```\n\nA prebuilt x86_64 version of this image is on GitHub:\n\n```sh\ndocker pull ghcr.io/fboulnois/pg_uuidv7:1.6.0\n```\n\nThe prebuilt image [is similar](https://github.com/fboulnois/pg_uuidv7/pull/29#issuecomment-1996102946)\nto a vanilla Postgres instance so the extension needs to be enabled manually or\nwith an initialization script with `CREATE EXTENSION pg_uuidv7;`.\n\n## Test\n\nA separate [`Dockerfile`](test/Dockerfile) is available to build the extension\nagainst a specific version of Postgres and run the regression tests:\n\n```sh\ndocker build . --file test/Dockerfile --tag pgxn-test\ndocker run --rm -it pgxn-test /bin/sh\n# once in container\npg-start 17\npg-build-test\n```\n\n## Contributing\n\nSee the [CONTRIBUTING.md](CONTRIBUTING.md) file for more details. In short,\nfollow the style guidelines, agree to the Developer Certificate of Origin, and\nsubmit a PR.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffboulnois%2Fpg_uuidv7","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffboulnois%2Fpg_uuidv7","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffboulnois%2Fpg_uuidv7/lists"}