pg_uuidv7
Create UUIDv7 values in postgres
Repository
fboulnois/pg_uuidv7
https://github.com/fboulnois/pg_uuidv7
Source
pg_uuidv7-1.7.0.tar.gz
pg_uuidv7-1.7.0.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_uuidv7 | 1.7.0 | FUNC | MPL-2.0 | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4540 | pg_uuidv7 | No | Yes | No | Yes | No | Yes | - |
| Related | pg_idkit pgx_ulid uuid-ossp sequential_uuids pg_hashids permuteseq |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | MIXED | 1.7.0 | 1817161514 | pg_uuidv7 | - |
| RPM | PGDG | 1.7.0 | 1817161514 | pg_uuidv7_$v | - |
| DEB | PIGSTY | 1.7.0 | 1817161514 | postgresql-$v-pg-uuidv7 | - |
Build
You can build the DEB packages for pg_uuidv7 using pig build:
pig build pkg pg_uuidv7 # build DEB packages
Install
You can install pg_uuidv7 directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pg_uuidv7; # Install for current active PG version
pig ext install -y pg_uuidv7 -v 18 # PG 18
pig ext install -y pg_uuidv7 -v 17 # PG 17
pig ext install -y pg_uuidv7 -v 16 # PG 16
pig ext install -y pg_uuidv7 -v 15 # PG 15
pig ext install -y pg_uuidv7 -v 14 # PG 14
dnf install -y pg_uuidv7_18 # PG 18
dnf install -y pg_uuidv7_17 # PG 17
dnf install -y pg_uuidv7_16 # PG 16
dnf install -y pg_uuidv7_15 # PG 15
dnf install -y pg_uuidv7_14 # PG 14
apt install -y postgresql-18-pg-uuidv7 # PG 18
apt install -y postgresql-17-pg-uuidv7 # PG 17
apt install -y postgresql-16-pg-uuidv7 # PG 16
apt install -y postgresql-15-pg-uuidv7 # PG 15
apt install -y postgresql-14-pg-uuidv7 # PG 14
Create Extension:
CREATE EXTENSION pg_uuidv7;
Usage
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
);
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.