{"id":21089190,"url":"https://github.com/rrmn/postgres-uuidv7","last_synced_at":"2026-02-14T12:37:13.554Z","repository":{"id":242334979,"uuid":"809290413","full_name":"rrmn/Postgres-UUIDv7","owner":"rrmn","description":"Add a UUIDv7 function to Postgres","archived":false,"fork":false,"pushed_at":"2024-06-02T09:27:59.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-05T05:39:52.054Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"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/rrmn.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}},"created_at":"2024-06-02T09:18:05.000Z","updated_at":"2024-06-02T09:28:02.000Z","dependencies_parsed_at":"2024-06-02T10:38:48.605Z","dependency_job_id":"8028da34-6556-4297-8bf3-d248b392cf07","html_url":"https://github.com/rrmn/Postgres-UUIDv7","commit_stats":null,"previous_names":["rrmn/postgres-uuidv7"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rrmn/Postgres-UUIDv7","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrmn%2FPostgres-UUIDv7","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrmn%2FPostgres-UUIDv7/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrmn%2FPostgres-UUIDv7/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrmn%2FPostgres-UUIDv7/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rrmn","download_url":"https://codeload.github.com/rrmn/Postgres-UUIDv7/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrmn%2FPostgres-UUIDv7/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29443495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T10:51:12.367Z","status":"ssl_error","status_checked_at":"2026-02-14T10:50:52.088Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-19T21:23:58.251Z","updated_at":"2026-02-14T12:37:13.535Z","avatar_url":"https://github.com/rrmn.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Postgres-UUIDv7\nAdd a UUIDv7 function to Postgres\n\n## Background\n\nTime-sortable UUIDs are awesome. \n\n\n## Create function \n\n```\nCREATE OR REPLACE FUNCTION generate_uuid7()\nRETURNS uuid AS $$\nDECLARE\n    unixts bigint;\n    msec bigint;\n    seq bigint;\n    rand bytea;\n    uuid_str text;\nBEGIN\n    -- Get UNIX timestamp in milliseconds\n    unixts := (EXTRACT(epoch FROM clock_timestamp()) * 1000)::bigint;\n\n    -- Generate random sequence counter (12 bits) and random data (62 bits)\n    seq := (get_byte(gen_random_bytes(2), 0) \u003c\u003c 8) | get_byte(gen_random_bytes(2), 1);\n    rand := gen_random_bytes(8); -- 8 bytes = 64 bits, will use 62 bits\n\n    -- Millisecond precision (12 bits)\n    msec := unixts \u0026 4095; -- Lower 12 bits of unixts\n\n    -- Shift unixts to get first 36 bits for timestamp\n    unixts := unixts \u003e\u003e 12;\n\n    -- Combine parts into UUID string\n    uuid_str := lpad(to_hex(unixts), 9, '0') ||             -- 36 bits for unixts\n                lpad(to_hex(msec), 3, '0') ||               -- 12 bits for msec\n                '7' ||                                      -- 4 bits for 'uuid version 7'\n                lpad(to_hex(seq), 3, '0') ||                -- 12 bits for sequence\n                lpad(to_hex((get_byte(rand, 0) \u0026 63) | 128), 2, '0') || -- Variant bits (2 bits) and first 6 bits of random data\n                encode(substring(rand from 2), 'hex');      -- Remaining random data (56 bits)\n\n    -- Format string to UUID spec\n    uuid_str := substr(uuid_str, 1, 8) || '-' ||\n                substr(uuid_str, 9, 4) || '-' ||\n                substr(uuid_str, 13, 4) || '-' ||\n                substr(uuid_str, 17, 4) || '-' ||\n                substr(uuid_str, 21, 12);\n\n    RETURN uuid(uuid_str);\nEND;\n$$ LANGUAGE plpgsql;\n\n```\n\n## Use function \n\n```\nSELECT generate_uuid7();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frrmn%2Fpostgres-uuidv7","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frrmn%2Fpostgres-uuidv7","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frrmn%2Fpostgres-uuidv7/lists"}