Skip to content
pg_uuidv7

pg_uuidv7

pg_uuidv7 : Create UUIDv7 values in postgres

Overview

ID Extension Package Version Category License Language
4520
pg_uuidv7
pg_uuidv7
1.7.0
FUNC
MPL-2.0
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
pg_idkit
pgx_ulid
uuid-ossp
sequential_uuids
pg_hashids
permuteseq

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
MIXED
1.7.0
18
17
16
15
14
pg_uuidv7 -
RPM
PGDG
1.7.0
18
17
16
15
14
pg_uuidv7_$v -
DEB
PIGSTY
1.7.0
18
17
16
15
14
postgresql-$v-pg-uuidv7 -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
el8.aarch64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
el9.x86_64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
el9.aarch64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
el10.x86_64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
el10.aarch64
PGDG 1.6.0
PGDG 1.6.0
PGDG 1.6.0
PGDG 1.6.0
PGDG 1.6.0
d12.x86_64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
d12.aarch64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
d13.x86_64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
d13.aarch64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
u22.x86_64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
u22.aarch64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
u24.x86_64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
u24.aarch64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
u26.x86_64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
u26.aarch64
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
PGDG 1.7.0
Package Version OS ORG SIZE File URL
pg_uuidv7_18 1.7.0 el8.x86_64 pgdg 21.7 KiB pg_uuidv7_18-1.7.0-1PGDG.rhel8.x86_64.rpm
pg_uuidv7_18 1.6.0 el8.x86_64 pgdg 21.2 KiB pg_uuidv7_18-1.6.0-2PGDG.rhel8.x86_64.rpm
pg_uuidv7_18 1.7.0 el8.aarch64 pgdg 21.8 KiB pg_uuidv7_18-1.7.0-1PGDG.rhel8.aarch64.rpm
pg_uuidv7_18 1.6.0 el8.aarch64 pgdg 21.3 KiB pg_uuidv7_18-1.6.0-2PGDG.rhel8.aarch64.rpm
pg_uuidv7_18 1.7.0 el9.x86_64 pgdg 21.2 KiB pg_uuidv7_18-1.7.0-1PGDG.rhel9.x86_64.rpm
pg_uuidv7_18 1.6.0 el9.x86_64 pgdg 21.3 KiB pg_uuidv7_18-1.6.0-2PGDG.rhel9.x86_64.rpm
pg_uuidv7_18 1.7.0 el9.aarch64 pgdg 21.0 KiB pg_uuidv7_18-1.7.0-1PGDG.rhel9.aarch64.rpm
pg_uuidv7_18 1.6.0 el9.aarch64 pgdg 21.1 KiB pg_uuidv7_18-1.6.0-2PGDG.rhel9.aarch64.rpm
pg_uuidv7_18 1.7.0 el10.x86_64 pgdg 21.5 KiB pg_uuidv7_18-1.7.0-1PGDG.rhel10.x86_64.rpm
pg_uuidv7_18 1.6.0 el10.x86_64 pgdg 21.6 KiB pg_uuidv7_18-1.6.0-2PGDG.rhel10.x86_64.rpm
pg_uuidv7_18 1.6.0 el10.aarch64 pgdg 21.7 KiB pg_uuidv7_18-1.6.0-2PGDG.rhel10.aarch64.rpm
postgresql-18-pg-uuidv7 1.7.0 d12.x86_64 pgdg 13.1 KiB postgresql-18-pg-uuidv7_1.7.0-1.pgdg12+1_amd64.deb
postgresql-18-pg-uuidv7 1.7.0 d12.x86_64 pigsty 17.8 KiB postgresql-18-pg-uuidv7_1.7.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-uuidv7 1.7.0 d12.aarch64 pgdg 13.3 KiB postgresql-18-pg-uuidv7_1.7.0-1.pgdg12+1_arm64.deb
postgresql-18-pg-uuidv7 1.7.0 d12.aarch64 pigsty 18.1 KiB postgresql-18-pg-uuidv7_1.7.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-uuidv7 1.7.0 d13.x86_64 pgdg 13.0 KiB postgresql-18-pg-uuidv7_1.7.0-1.pgdg13+1_amd64.deb
postgresql-18-pg-uuidv7 1.7.0 d13.x86_64 pigsty 17.8 KiB postgresql-18-pg-uuidv7_1.7.0-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-uuidv7 1.7.0 d13.aarch64 pgdg 13.3 KiB postgresql-18-pg-uuidv7_1.7.0-1.pgdg13+1_arm64.deb
postgresql-18-pg-uuidv7 1.7.0 d13.aarch64 pigsty 18.1 KiB postgresql-18-pg-uuidv7_1.7.0-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-uuidv7 1.7.0 u22.x86_64 pgdg 12.2 KiB postgresql-18-pg-uuidv7_1.7.0-1.pgdg22.04+1_amd64.deb
postgresql-18-pg-uuidv7 1.7.0 u22.x86_64 pigsty 17.7 KiB postgresql-18-pg-uuidv7_1.7.0-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-uuidv7 1.7.0 u22.aarch64 pgdg 12.1 KiB postgresql-18-pg-uuidv7_1.7.0-1.pgdg22.04+1_arm64.deb
postgresql-18-pg-uuidv7 1.7.0 u22.aarch64 pigsty 17.6 KiB postgresql-18-pg-uuidv7_1.7.0-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-uuidv7 1.7.0 u24.x86_64 pgdg 12.3 KiB postgresql-18-pg-uuidv7_1.7.0-1.pgdg24.04+1_amd64.deb
postgresql-18-pg-uuidv7 1.7.0 u24.x86_64 pigsty 17.8 KiB postgresql-18-pg-uuidv7_1.7.0-1PIGSTY~noble_amd64.deb
postgresql-18-pg-uuidv7 1.7.0 u24.aarch64 pgdg 12.5 KiB postgresql-18-pg-uuidv7_1.7.0-1.pgdg24.04+1_arm64.deb
postgresql-18-pg-uuidv7 1.7.0 u24.aarch64 pigsty 17.7 KiB postgresql-18-pg-uuidv7_1.7.0-1PIGSTY~noble_arm64.deb
postgresql-18-pg-uuidv7 1.7.0 u26.x86_64 pgdg 12.6 KiB postgresql-18-pg-uuidv7_1.7.0-1.pgdg26.04+1_amd64.deb
postgresql-18-pg-uuidv7 1.7.0 u26.x86_64 pigsty 18.2 KiB postgresql-18-pg-uuidv7_1.7.0-1PIGSTY~resolute_amd64.deb
postgresql-18-pg-uuidv7 1.7.0 u26.aarch64 pgdg 12.5 KiB postgresql-18-pg-uuidv7_1.7.0-1.pgdg26.04+1_arm64.deb
postgresql-18-pg-uuidv7 1.7.0 u26.aarch64 pigsty 17.7 KiB postgresql-18-pg-uuidv7_1.7.0-1PIGSTY~resolute_arm64.deb

Source

pig build pkg pg_uuidv7;		# build deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_uuidv7;		# install via package name, for the active PG version

pig install pg_uuidv7 -v 18;   # install for PG 18
pig install pg_uuidv7 -v 17;   # install for PG 17
pig install pg_uuidv7 -v 16;   # install for PG 16
pig install pg_uuidv7 -v 15;   # install for PG 15
pig install pg_uuidv7 -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pg_uuidv7;

Usage

pg_uuidv7: Create valid version 7 UUIDs in PostgreSQL

CREATE EXTENSION pg_uuidv7;

Functions

Function Description
uuid_generate_v7() Generate a new UUIDv7
uuid_v7_to_timestamptz(uuid) Extract the timestamp from a UUIDv7
uuid_timestamptz_to_v7(timestamptz [, bool]) Convert a timestamp to a UUIDv7 (set second arg to true to zero the random bits)

Examples

-- Generate a UUIDv7
SELECT uuid_generate_v7();
-- 018570bb-4a7d-7c7e-8df4-6d47afd8c8fc

-- Extract timestamp from UUIDv7
SELECT uuid_v7_to_timestamptz('018570bb-4a7d-7c7e-8df4-6d47afd8c8fc');
-- 2023-01-02 04:26:40.637+00

-- Convert timestamp to UUIDv7
SELECT uuid_timestamptz_to_v7('2023-01-02 04:26:40.637+00');
-- 018570bb-4a7d-7630-a5c4-89b795024c5d

-- For date range queries, zero the random bits
SELECT uuid_timestamptz_to_v7('2023-01-02 04:26:40.637+00', true);
-- 018570bb-4a7d-7000-8000-000000000000

-- Use as primary key
CREATE TABLE events (
  id uuid NOT NULL DEFAULT uuid_generate_v7() PRIMARY KEY,
  data text
);
Last updated on