Quickstart
Create a table that assigns a UUIDv7 to each new row. First install version 0.0.4 into extensions. Run these statements as a role that can create a table and call the extension functions.
Create a table
Section titled “Create a table”create table notes ( id uuid primary key default extensions.gen_random_uuid_v7(), body text not null, created_at timestamptz not null default clock_timestamp());The primary key enforces uniqueness. created_at records an explicit application timestamp; it does not depend on decoding the ID.
Insert and read
Section titled “Insert and read”insert into notes (body)values ('My first note'), ('Another note')returning id, body, created_at;-- Two rows, each with its own generated UUID.
select id, bodyfrom notesorder by created_at, id;Omit id to use the default. Supplying null does not invoke the default and fails the primary key’s not-null constraint.
Inspect the encoded time
Section titled “Inspect the encoded time”select id, extensions.timestamp_from_uuid_v7(uuid_v7 => id)from notes;-- A timestamp without time zone, expressed in UTC.The extracted time has whole-second precision in 0.0.4 and can differ from created_at. See read timestamps.
Next, choose an ID or learn about primary keys and pagination.