pg_uuidv7
pg_uuidv7
pg_uuidv7 : Create UUIDv7 values in postgres
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4540 | 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
|
Source
pig build pkg pg_uuidv7; # build debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Create this extension with:
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
);Last updated on