Alper Sarı

PostgreSQL 18 UUIDv7 and Virtual Generated Columns: Two Quietly Practical Features

PostgreSQL 18 added two features that can simplify application data models: a built-in uuidv7() function and virtual generated columns. Neither is a reason to rewrite a stable schema, but both are worth considering when a table or read model is already changing.

UUIDv7 places time-ordering information in the identifier. Compared with randomly distributed UUIDv4 values, time-ordered identifiers can improve locality for B-tree inserts and make recently created records cluster more naturally. They can also reveal approximate creation order, so consider whether that is acceptable for identifiers exposed outside the system. They are not a replacement for an explicit timestamp, and they do not prove authorization or ownership.

Virtual generated columns compute their value when read rather than storing a second copy in the row. They can make a derived field available through a normal column interface, which helps with query readability and consistent expressions. Since the value is recomputed, frequently accessed expressions may still need an index or a stored generated column. Compare the cost of recalculation with the storage and write cost of persisting the result.

For an existing UUID primary key, migration is a product and operations decision. Changing identifier generation affects every writer: web processes, imports, jobs, and downstream services. A safe transition might adopt UUIDv7 only for new records, while preserving existing keys, or add a new key only when there is a clear compatibility need. Test sorting assumptions, replication, API clients, and backup/restore before deployment.

PostgreSQL 18’s release announcement introduces uuidv7() and virtual generated columns. Consult the UUID functions and generated columns documentation for exact behavior.