Pure SQL functions to use UUIDs v7 in PostgreSQL.
The functions are packaged as an extension ("uuidv7-sql") for convenience, but they may also be created individually by sourcing all or parts of the creation script.
The Makefile uses the PGXS infrastructure
To make the extension available to a PostgreSQL server:
$ [sudo] make install
The same, but targeting a specific PostgreSQL installation:
$ [sudo] make PG_CONFIG=/path/to/pg_config install
To activate the extension in the target databases:
CREATE EXTENSION "uuidv7-sql";
Generate a UUID v7 value using the current time with millisecond precision and 74 bits of randomness.
Generate a UUID v7 value using the given time with millisecond precision and 74 bits of randomness.
Generate a UUID v7 value using the current time with sub-millisecond precision (up to 0.25 µs), with 62 bits of randomness.
Generate a UUID v7 value using the given time with sub-millisecond precision (up to 0.25 µs), with 62 bits of randomness.
Extract the timestamp with millisecond precision from the given UUID v7 value.
Generate a non-random uuidv7 with the given timestamp (first 48 bits) and all random bits to 0. As the smallest possible uuidv7 for that timestamp, it may be used as a boundary for tables partitioned by ranges of UUID.