uuidv7-sql
Pure SQL and PL/pgSQL functions for generating, inspecting, and transforming UUID version 7 values.
postgres-uuidv7-sql · Pure SQL and PL/pgSQL functions for generating, inspecting, and transforming UUID version 7 values.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 101250 | uuidv7-sql | postgres-uuidv7-sql | 1.1 | FUNC | PostgreSQL | SQL |
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
- Upstream README
- Version 1.0 generation functions
- Version 1.1 encryption functions
- Version 1.1 control file
- PostgreSQL 18 UUID functions
uuidv7-sql 1.1 is a pure-SQL implementation of UUIDv7 generation, timestamp extraction, range boundaries, sub-millisecond variants, and reversible UUIDv4 or UUIDv8 transformation.
Generate and inspect
Install in an explicit schema so calls remain unambiguous on PostgreSQL 18 and later:
PostgreSQL 18 includes a pg_catalog uuidv7 function that wins normal name resolution. Prefer the built-in function for ordinary generation, or schema-qualify this extension’s version as shown.
Caveats
- UUIDv7 exposes its creation timestamp. Do not place raw values in contexts where approximate event time is sensitive.
- Values generated within the same millisecond contain random ordering bits and are not guaranteed to be strictly increasing. The sub-millisecond variant also does not provide a global monotonic sequence.
- uuidv7_extract_timestamp does not verify the input version or variant; it interprets the first 48 bits of any UUID as milliseconds.
- uuidv7_boundary is deterministic and non-random. Use it only as a range bound, never as a row identifier.
- Version 1.1’s XTEA transformation is a reversible, unauthenticated 64-bit block construction, not general authenticated encryption. It does not detect tampering, define key storage or rotation, or validate that input is UUIDv7; SQL-supplied keys can also appear in logs and activity views.
- Generation depends on gen_random_uuid, which is built into PostgreSQL 13 and later; older releases need pgcrypto even though the control file does not declare that dependency.
- The repository contains no automated tests. Validate RFC conformance, timestamp boundaries, time zones, supported date range, encryption round trips, and upgrade from 1.0 before relying on it.